-
Notifications
You must be signed in to change notification settings - Fork 95
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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 = [] |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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)): |
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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]: |
There was a problem hiding this comment.
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)
...
No description provided.