21
Pavel
https://pavelmorava.com/
Last seen 11 months ago
Member for 10 years, 6 months
Difficulty Normal
Author of Sovereign
https://www.royalroad.com/fiction/26615/sovereign
My blog
https://pavelmorava.com/
if (lstLen % 2):
return sortedLst[index]
else:
return (sortedLst[index] + sortedLst[index + 1])/2.0
return data[0]
might be replaced by:
return sortedLst[index] if lstLen % 2 else return sum(sortedLst[index:index+2])/2
L
More
You should not used \ to break code into more lines.
Just use () like this:
return ("FizzBuzz
...
...
...)
It is safer and simpler.
More
You should change your category to Creative :) Well, it is overcomplicated. But nice :)
More
I timeit (number = 100000) your solution vs mine:
Mine: 0.5550804549334346
Yours: 0.8051685473980223
I was not so bold to put mine into Speedy :) And yours should not be in Speedy as well.
I agree that deque.popleft() should be faster than list.pop(0) but from my point of view you are us
More
Well, similar to me, but I tried to avoid double calling of int(). I thought it is better to call function rather once than twice. Am I correct? Or it doesnt matter? I mean generally, not in this easy tasks.
More
Line 1 and 2
def count_words(text, words):
''' (str, set) -> int
can be merged together like this to get rid of line 2
def count_words(text: str, words:set) -> int:
I dont why it is sparely used feature. Hope it helps :)
More
I have to admit in public there are only two names for me related to Python: Guido and Veky. Not necessary in this order. Stay cool, both of you :)
More
Good work. But you dont need to convert your numbers to string in this task.
PS: I když já to udělal taky :)
More
You can split line 4 safely. In python statement in brackets can be multilined. I am using this style:
(chr(ord(paw[0]) + 1) +
str(int(paw[1]) - 1)) in
pawns or (chr(ord(paw[0]) -1) +
str(int(paw[1]) - 1)) in pawns:
I believe it is clearer :)
By the way, check this book:
h
More
for row_offset, col_offset in (
(-1, -1), (-1, 0), (-1, 1),
( 0, -1), ( 0, 1),
( 1, -1), ( 1, 0), ( 1, 1)
)
I like that clear style :) It is put nicely.
More
You are trying too hard :)
What about simplifying your solution? There is no reason to have
def __add_connections(self, connections):
for connection in connections:
self.add(connection)
More