30
bravebug
9 29 55 Leader of the month
4712/ 5195
Leonid Selivanov
Last seen 1 month ago
Member for 10 years, 12 days
Difficulty Normal
Best reviews / Newest reviews
First-jusha 3
No need for the first "return" in "if" execution in this case. More
Single line solution (almost ^-^)-Lucaum_CF 2
Strings in python are iterative. You don't need to preconvert them to a list: >>> from string import ascii_lowercase >>> ascii_lowercase 'abcdefghijklmnopqrstuvwxyz' >>> set(ascii_lowercase) {'q', 'z', 'm', 'e', 'i', 'd', 'p', 'k', 'o', 'c', 'r', 'b', 'w', 'l', 'g', 'n', 'u', 'x More
Str.Split-Detka_v_Ogne 2 2
In this case: answer = text.split()[0] give the same result. You can read about this in the documentation: https://docs.python.org/3.8/library/stdtypes.html#str.split More
First-jusha 2
You used a very intricate algorithm to determine the indexes. It would be convenient to use enumerate() function in case of this solution: for i, n in enumerate(items): if n == 0: zind.append(i) Or with list comprehension: zind = [i for i, n in enumerate(items) if n = More
First-robertabegg 1 1
**def morse_digit** is magic! Thanks! More
simple and clean-leshchenko 1 1
raise ("%s - number expected after the command" % cmd) not correct expression More
How to Find Friends-tssrkt777 1 1
Сlass "Friends" essentially combines a list and two functions (two because lists have their own "clear" method), only one instance is used, all methods are "classmethod". It would be easier to use a global list and two global functions I think. This looks like an incorrect use of classes. More
math.ceil-qwertyaos 1
The code would be faster and more readable if you put repeated calculations in a variable: num = math.ceil(len(items)/2) return [items[:num], items[num:]] More
bool([x])-David_Jones 1
But bool() is do nothing in this case =) This is equal to: return not num % 2 More
First-zxcv 1 1
This part of the code: int(d if d[0] != '0' else d[1]) can be replaced with: int(d) Because: >>> int("9") 9 >>> int("09") 9 But it would be best to use: from datetime import datetime t = datetime.strptime(t, "%H:%M") Good luck to learn! More
Golden Pyramid-JimmyCarlos 1
An interesting algorithm! Thanks! One note: PEP8 recommends using lowercase letters for function and variable names. More
First-____247 1 1
In this case no need for use str() function. format() returns a string: print(type(format(4,"b"))) More
First-johankor 1 1
Some code is repeated several times. This could have been avoided, for example: for i in range(1, len(data)): if data[i] - data[i - 1] != 1: res.append((s, e)) s = data[i] e = data[i] else: res.append((s, e)) "else" when used with the "for" l More
With itertools.chain-vvm70 1 1
I don't understand what the joke is? After all, the code works perfectly without a "chain" function. def expand_intervals(items): return [x for it in items for x in range(it[0], it[1] + 1)] More
Jump the gibberish-Krischtopp 1 1
Good idea: just changing indexes! Thanks! More
First-fs0000016 1 1
Good and simple re solution. Thanks! More
First-paka 1
Strings have a built in isupper() method: "PYTHON IS 1'ST CODING L@NG!".isupper() # True "PYTHON IS 1'ST CODING L@NG! AND a".isupper() # False More
First-____247 1 1
This solution can have few optimizations. First you don't need capital letters at all. text = text.lower() "freq" list generates duplicate values. To get rid of this, and at the same time from the unnecessary variable "frset", you can immediately use set() in list comprehension: freq=[(i More
First-____247 1 1
The "sorted" function, as well as "map" and "filter" as the key, can accept any function name that will be applied to the original value and return some other value that will be used for sorting. So: list=sorted([i for i in numbers_array], key=lambda x:abs(x)) is equal: list=sorted([i for More
First-vvm70 1
datetime from datetime have a cool method "strptime". It allow to make datetime object from string of date or string of date and time in any format: def age(self): return (datetime.strptime("01.01.2018", "%d.%m.%Y") - datetime.strptime(self.birth_date, "%d.%m.%Y")).days // 365 Hav More
1
2 3 4