Browse Source

Reduce

pull/9/head
Jure Šorn 5 years ago
parent
commit
bf479ad661
1 changed files with 2 additions and 2 deletions
  1. 4
      README.md

4
README.md

@ -39,7 +39,7 @@ sorted_by_second = sorted(<list>, key=lambda el: el[1])
sorted_by_both = sorted(<list>, key=lambda el: (el[1], el[0])) sorted_by_both = sorted(<list>, key=lambda el: (el[1], el[0]))
flattened_list = list(itertools.chain.from_iterable(<list>)) flattened_list = list(itertools.chain.from_iterable(<list>))
list_of_chars = list(<str>) list_of_chars = list(<str>)
product_of_elems = functools.reduce(lambda agr, x: agr * x, <list>)
product_of_elems = functools.reduce(lambda out, x: out * x, <list>)
no_duplicates = list(dict.fromkeys(<list>)) no_duplicates = list(dict.fromkeys(<list>))
``` ```
@ -481,7 +481,7 @@ for i in range(10):
from functools import reduce from functools import reduce
<iter> = map(lambda x: x + 1, range(10)) # (1, 2, ..., 10) <iter> = map(lambda x: x + 1, range(10)) # (1, 2, ..., 10)
<iter> = filter(lambda x: x > 5, range(10)) # (6, 7, ..., 9) <iter> = filter(lambda x: x > 5, range(10)) # (6, 7, ..., 9)
<any_type> = reduce(lambda agr, x: agr + x, range(10)) # 45
<any_type> = reduce(lambda out, x: out + x, range(10)) # 45
``` ```
### Any, All ### Any, All

Loading…
Cancel
Save