python generator cheat sheet download

Solutions on MaxInterview for python generator cheat sheet download by the best coders in the world

showing results for - "python generator cheat sheet download"
Maite
28 Sep 2016
1>>> permutations('abc', 2)                   #   a  b  c
2[('a', 'b'), ('a', 'c'),                     # a .  x  x
3 ('b', 'a'), ('b', 'c'),                     # b x  .  x
4 ('c', 'a'), ('c', 'b')]                     # c x  x  .
5
Emma
30 Aug 2018
1>>> multiply_by_3 = get_multiplier(3)
2>>> multiply_by_3(10)
330
4
Delfina
04 Mar 2020
1class <name>:
2    def __init__(self, a):
3        self.a = a
4    def __repr__(self):
5        class_name = self.__class__.__name__
6        return f'{class_name}({self.a!r})'
7    def __str__(self):
8        return str(self.a)
9
10    @classmethod
11    def get_class_name(cls):
12        return cls.__name__
13
Irwin
13 Jan 2017
1>>> counter = count(10, 2)
2>>> next(counter), next(counter), next(counter)
3(10, 12, 14)
4
Bentley
06 Nov 2016
1from functools import wraps
2
3def debug(print_result=False):
4    def decorator(func):
5        @wraps(func)
6        def out(*args, **kwargs):
7            result = func(*args, **kwargs)
8            print(func.__name__, result if print_result else '')
9            return result
10        return out
11    return decorator
12
13@debug(print_result=True)
14def add(x, y):
15    return x + y
16
Gabriela
09 Jul 2016
1def get_multiplier(a):
2    def out(b):
3        return a * b
4    return out
5
Valerio
30 Jul 2020
1>>> combinations_with_replacement('abc', 2)  #   a  b  c
2[('a', 'a'), ('a', 'b'), ('a', 'c'),         # a x  x  x
3 ('b', 'b'), ('b', 'c'),                     # b .  x  x
4 ('c', 'c')]                                 # c .  .  x
5
Lyric
01 Mar 2020
1class Person:
2    def __init__(self, name, age):
3        self.name = name
4        self.age  = age
5
6class Employee(Person):
7    def __init__(self, name, age, staff_num):
8        super().__init__(name, age)
9        self.staff_num = staff_num
10
Janelle
27 Sep 2020
1from functools import wraps
2
3def debug(func):
4    @wraps(func)
5    def out(*args, **kwargs):
6        print(func.__name__)
7        return func(*args, **kwargs)
8    return out
9
10@debug
11def add(x, y):
12    return x + y
13
Henry
01 Jun 2016
1from itertools import count, repeat, cycle, chain, islice
2