from operator import itemgetter as ig
list(map(ig('name'), sorted(players, key=ig('score'))))
for i, table in enumerate(pd.read_html('http://www.statdata.ru/nasel_regions')):
print('-' * 100, f'>>>{i}', table, sep='\n')
from functools import reduce
from operator import pow, add
# Вариант #1
print(reduce(lambda result, vals: result + [pow(sum(vals), 1/3)], zip(lst1, lst2), []))
# Вариант #2
print(list(map(lambda x: pow(x, 1/3), map(add, lst1, lst2))))
Performing list(d) on a dictionary returns a list of all the keys used in the dictionary, in insertion order (if you want it sorted, just use sorted(d) instead). To check whether a single key is in the dictionary, use the in keyword.
list(dict.fromkeys(my_list))
class Element:
recipes = {
('Aqua', 'Air'): 'Storm',
('Aqua', 'Fire'): 'Steam',
('Aqua', 'Earth'): 'Dirt',
('Air', 'Fire'): 'Lightning',
('Air', 'Earth'): 'Dust',
('Fire', 'Earth'): 'Lava',
}
recipes.update({(b, a): c for (a, b), c in recipes.items()})
classes = {a for a, b in recipes.keys()} | {*recipes.values()}
@classmethod
def __str__(cls):
return cls.__name__
def __add__(self, other):
if isinstance(other, self.__class__):
return self
try:
return eval(self.recipes[(str(self), str(other))])()
except KeyError:
return None
for cls in Element.classes:
exec(f'class {cls}(Element): pass')
print(Air() + Aqua())
from itertools import takewhile, dropwhile, compress
for match in re.finditer('\[(?P<my_tag>[\w\d]+)\](.*?)\[/(?P=my_tag)\]', val):
if match:
print(match.group(2))
from collections import Counter
from operator import itemgetter
Counter(map(itemgetter('first_name'), students))
Counter(map(lambda student: student['first_name'], students))
def syllables(word, vowels=set('aeiou'), end='!'):
word = iter(word + end)
b, syllables = next(word), ''
while b != end:
a, b = b, next(word)
syllables += a
if (a in vowels) and (b not in vowels):
syllables += ' '
return syllables.split()
syllables('daabdhvoovuudpanda')