43
Dmitry Khromenko
Last seen 1 day ago
Member for 3 years, 4 months, 17 days
Difficulty Normal
I study Python myself and help my son and daughter learn programming.
Good work!
Also you can use flag "re.IGNORECASE"
import re
def checkio(words):
return bool(re.search(r"[a-z]+ [a-z]+ [a-z]+", words, re.IGNORECASE))
More
Suitable place to use **yield**
def find_divisors(n):
for i in range(1, n):
if n % i == 0:
yield i
More
instead "total_time = datetime(2010, 1, 1, 1, 1, 1) - datetime(2010, 1, 1, 1, 1, 1)"
you can use "total_time = timedelta()"
More
sorted(array, key=lambda x: (x[0], len(x)))
before sorted - ['bac', 'aaaaa', 'av']
after sorted - ['av', 'aaaaa', 'bac']
Key as a function that returns a tuple (x[0], len(x)). The tuple values is different for different elements of array. '-' minus really works like reverse, this is a
More
intresting construction =) - [item for item in items if item]
More
h, m, s = ((int(n)//10, int(n)%10) for n in time_string.split(':'))
Did well!
More
a little shorter -
lower().replace("m", ".m.")
instead of -
replace("AM", "a.m.").replace("PM", "p.m.")
More