22
Last seen 5 years ago
Member for 8 years, 4 months
Difficulty Normal
Would like to receive comments/critics of my published solutions.
Some simplification you might find useful:
Line 6: when splitting by whitespace, you can write just: something.split()
...but here you don't even have to split, because you always append just the last (one) character, so that line becomes:
q.append(com[-1])
---
Line 8: empty list returns
More
Lines 7 and 8 - instead of writing else and then if, there is 'elif' that does exactly that. Also, you can check if there's something in 'queue' by knowing that empty list returns false, so your else-part now becomes:
elif queue:
queue.pop(0)
More
Lines 6 and 7 - you always append just the last (one) character, so there's no need for splitting 'item' and creating temp, you could just do:
dedede.append(item[-1])
Lines 8 - 12: I see no point in lines 11 and 12, and you can have only one (el)if to cover both conditions:
elif "POP" in
More
There are couple of missions here where you'll need to transpose a matrix, so I think it's a valuable to know an elegant way to do so (it could have saved you some time and trouble here):
transposed = list(zip(*matrix))
More
Line 8 - there's no need for list comprehension from the existing list of factors, you can just do:
return int(''.join(reversed(factors)))
(I prefer 'reversed' rather than 'sorted' because we know for sure that list of factors is in descending order)
More
There are couple of missions here where you’ll need to transpose a matrix, so I think it’s a valuable to know an elegant way to do so - your line 3 can be written as:
sum_col = [sum(x) for x in zip(*lst)]
More
Rather than creating a list of unique elements and then removing those elements from the original list, wouldn't it be better to just create a list of non-unique elements and return that?
def checkio(data):
i = []
for x in data:
if data.count(x) > 1:
More
More pythonic way of lines 7-9 is without 'temp' variable, by doing:
alist[i], alist[i+1] = alist[i+1], alist[i]
More
More pythonic way of lines 7-9 is without 'disposal' variable, by doing:
check[i-1], check[i] = check[i] = check[i-1]
More
Lines 14-20 could be replaced with a simple:
return first_word_list == second_word_list
More
Instead of returning `i + 1` (line 6), you could have passed `1` as a second argument to the `enumerate` function (line 4), which is a starting index (the default value is 0), and then return just `i`, which is more elegant.
More