22
Last seen 5 years ago
Member for 8 years, 4 months
Difficulty Normal
Would like to receive comments/critics of my published solutions.
If you slightly correct your line 6:
return max(args) - min(args)
there's no need for lines 2 and 3 ;)
More
You might want to know about [zip](https://docs.python.org/3/library/functions.html#zip). Check other solutions for its usage here.
More
Line 5, just check it like this:
if queue:
Line 8:
queue.append(s[-1])
Lines 9-12:
return ''.join(queue)
More
You could have avoided removing the last comma if you chose new array to be a list, not a string. Also, having temp_array is not needed.
So you can remove lines 10, 12, 13, 19 and now your lines 14 and 21 would look like this:
14: new_array.append(str(n) + str(n+1))
.....
21: return '
More
If you would like to avoid deleting that last ',' - a better idea would be to store each phrase in a list, and then return a string of all phrases in a list, separated by ',':
word = []
for phrase in phrases:
word.append(phrase.replace("right", "left"))
return ','.join(word)
More
Line 10 could be written as:
string += "," + item.replace("right","left")
But you could have avoided all that trouble of checking if 'string' is empty or not, if you decided to make 'string' a list:
string = []
for item in phrases:
string.append(item.replace("right", "left"))
More
','.join(phrases) is already a string, no need to convert it - you can remove that 'str' at the beginning of the line.
More
If you used 'enumerate' in your line 3:
for i, word in enumerate(words_list):
your lines 4, 6 and 7 would have looked much nicer. For example, line 7:
words_list[i+2].isalpha():
More
Line 5 - Python way of checking if something is empty:
if not li:
But, instead of checking if something is in your list, you could have directly checked if there's something in args, and if there is, find max and min of args - so you don't need your first three lines where you create 'li':
More
Pythonic way of checking if something is empty: (line 2)
if not args:
Also, there exist 'min' and 'max' functions, which give you min and max value, no need to sort and pick first and last item:
return max(args) - min(args)
More
There exist 'min' and 'max' functions, which give you min and max value, no need to sort and pick first and last item:
return max(tabela) - min(tabela)
Having that said - there's no need to create tabela - in line 6 you could check 'if not args' and then in line 9 just return difference betwee
More
There exist ‘min’ and ‘max’ functions, which give you min and max value, no need to reinvent them (plus, it’s a bad practice to call your variables the same as built-in functions)
More
There exist 'min' and 'max' functions, which give you min and max value, no need to sort and pick first and last item:
return max(args) - min(args)
More
There exist ‘min’ and ‘max’ functions, which give you min and max value, no need to reinvent them (plus, it’s a bad practice to call your variables the same as built-in functions)
More
Lines 6 and 7 - you don't have to type all that:
from string import ascii_lowercase
alpha = list(ascii_lowercase)
More