22
Dahlia Ramm
Last seen 1 year ago
Member for 8 years, 1 month, 3 days
Difficulty Normal
Nice one!
Why are u using _**key=lambda x: abs(x)**_ instead of _**key=abs**_ ?
Instead of casting "numbers_array" to a list, i guess udid this to use list.sort(),
u could have used the bult-in function sorted().
sorted() also takes key functions **and** it can deal with any iterable as it returns
More
Line 2:
if not len(data): return 0
Calling len(data) is unnecessary!
if not data: return 0
does the same, and follows PEP8.
More
Line 3:
n = str(bin(num))[2:]
bin() already returns a string, so there is no need to cast it!
Slicing away "0b" also makes no sence as it never effects the result.
Instead of using a for-loop to count the unities, you could return n.count("1")
More
Why are u doing this?
> list(zip(*data))
already returns the transposed matrix as a 2D-List.
More
Line 6:
if (number%5) == 0 and (number%3) == 0:
the least common multiple of 2 and 5 is 15, so:
if number & 15 == 0:
will give the correct result with less code.
The "elif" in line 8 and 10 should be "if", because if the expression before evaluates to true
they will never be reached.
Lin
More
I like it, even though its a bit complicated.
But I had no idea that's it possible to use tuple as index for dictionary... learned something.
More
Nice!
But in line 10:
fib_seq = fibo(20)
you are generating the first 20 fibonacci numbers, that's more you ever need
Ge.nerating the next Fibonacci number only if you need it makes more sense.
More
You are generating more fibonacci numbers then you might need, I think it makes more sense to only generate the next fibonacci number it there is need to do so.
Is a dictionary the proper type to store your result?
The older the ghost gets, the more kv pairs are in your dict, even thoungh will only
More
What's bad about this solution?
When the ghosts age is 55 the while-loop will be executed 55 times...
When the ghosts age is 4689 the while-loop will be executed 4689 times...
Needs a second try...
More
Line 2:
... lambda numbers_array: numbers_array if (numbers_array > 0) else -numbers_array)...
Have a look at the [built-in function abs()](https://docs.python.org/3.6/library/functions.html#abs). ;)
More
Line 5:
counted = data.count(i) # count the number of occurences of unique item
How often can a **unique** number occur?
More
return bin(number)[2:].count('1')
You are slicing away the first 2 chracters of the string bin(number) returns.
Is that necessary? will one of these character ever be "1"?
More
Is the numpy.bitwise_xor() more effective then the bitwise xor operator "^"?
More
Line 19:
return str(answer)
do you need to type cast answer to string here?
Line 11:
if number % 3 == 0 and number % 5 == 0:
when you use the least common multiple of 3 and 5 you can get rid of the "and" comparison.
if number % 15 == 0:
More
Clear!
Line 6:
if number % 3 == 0 and number % 5 == 0:
what about the least common multiple of 3 and 5?
if number % 15 == 0:
More
Line 3:
if len(splitted) == 0:
this "if" is redundant, len(splitted) can never be 0.
Besides that if you ever want to check whether a sequence is empty or not use:
if sequence:
do something
if the sequence is empty, this "if" evaluates to **False** otherwise to **True**
Line 14 to
More
Clear!
Instead of type casting the tuple to a list manually you could have used the [built-in function sorted()](https://docs.python.org/3.6/library/functions.html#sorted).
You can pass iterable to this function and it returns a list.
More