Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solutions to problems 1.3 - 1.6 #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lomeli-noe
Copy link

No description provided.

Copy link
Contributor

@lhchavez lhchavez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit about code review etiquette: normally you want to keep all your changes small. by splitting your change in smaller chunks you'll be able to make progress faster since non-controversial chunks will be approved and merged faster. since each individual program is independent of each other, it is ideal to make each one be its own review. you'll get better mileage out of the small network of (volunteer!) reviewers.

and another tip: try running a code formatter like yapf so that it has consistent use of space. that way the code review can focus on actual content and less on presentation. try also running flake8 on your code so that it catches some common style mistakes.

temp.append(string[i])
return ''.join(temp)

print(Urlify("Mr John Smith ", 13))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use the unittest library since that will let you know when a test fails instead of you having to manually go through the output.


def Urlify(string, size):
temp = []
url = '%20'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe call this something a bit better, like encoded_space, since this is not an URL.

# "Mr John Smith ", 13 => "Mr%20John%20Smith"

def Urlify(string, size):
temp = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be better to give this a more descriptive name than temp. something like urlified could work.

def Urlify(string, size):
temp = []
url = '%20'
for i in range(size):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be more Pythonic to use

for c in string[:size]:

uniq = set(c for c in str)

if len(str) % 2 != 0:
return (len(str) / 2)+1 == len(uniq)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try using yapf to format your code so that the spacing between operators is consistent.

print(PalinPerm("reca Cra"))
print(PalinPerm("Taco dog"))
print(PalinPerm("ab Ba"))
print(PalinPerm("abcdba"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would the answer to PalinPerm("abaa") be?

print(OneAway("pale", "ple"))
print(OneAway("pales", "pale"))
print(OneAway("pale", "bale"))
print(OneAway("pale", "bake"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should the answer to OneAway("aaaaaaaaaaaaaaaaaaaa", "a") be?

result = []
cur = st[0]
count = 0
for i in range(len(st)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that you don't use the index (by itself) for anything, it's better to do:

for c in st:

if you find yourself needing both the index and the character, you can use

for i, c in enumerate(st):

print(stringCompress("aabcccccaaa"))
print(stringCompress("aabca"))
print(stringCompress("XxxyyyZZzzzzz"))
print(stringCompress("abc"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should the answer to

stringCompress("")

be?

cur = st[0]
count = 0
for i in range(len(st)):
if cur == st[i]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the guard clause pattern:

if cur == c:
  count += 1
  continue
# rest of the code
result.append(cur)
...

@FrancesCoronel FrancesCoronel added this to Reviewer approved in Data Structures & Algorithms Apr 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Data Structures & Algorithms
  
Reviewer approved
Development

Successfully merging this pull request may close these issues.

None yet

2 participants