+ 7
8th Sep 2018, 1:10 PM
I Am Arthur
I Am Arthur - avatar
14 Respuestas
+ 15
Maybe that's what you're trying to do ? a = [1,2,3] b = [4,7,5] ab = [*map(lambda x:x[0]*x[1],[*zip(a,b)])] print(ab)
8th Sep 2018, 3:13 PM
Cépagrave
Cépagrave - avatar
+ 11
The '*' aka 'star operator' or more accurately named: 'extended call syntax' placed before something (sequence or collection), will unpack it. A very simple example is : print([1,2,3]) will print the list as one element. print(*[1,2,3]) will unpack the list and print the 3 elements one after the other, just as : print(1,2,3) would do. In my example, [*map(...)] does the same as list(map(...)).
8th Sep 2018, 11:42 PM
Cépagrave
Cépagrave - avatar
+ 9
Zip is taking elements from multiple arrays and organises them in new arrays : all first elements together, then all second el, etc ... list(zip([1,2,3],[4,5,6])) returns [(1,4),(2,5),(3,6)]
10th Sep 2018, 8:40 PM
Cépagrave
Cépagrave - avatar
+ 8
a, b = list(map(lambda x: list(map(int, x)),[a,b]))
8th Sep 2018, 1:40 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 8
bases. class A(B, C): pass type('A', (B, C), {})
24th Dec 2018, 2:02 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 7
Flandre Scarlet you can give 'type' 3 args too. A = type('A', (), {'__init__': lambda self, a: setattr(self, 'a', a)}) """ Equivalent to class A: def __init__(self, a): self.a = a """ x = A(3) print(x.a)
24th Dec 2018, 1:56 PM
Mert Yazıcı
Mert Yazıcı - avatar
24th Dec 2018, 5:03 AM
Flandre Scarlet
Flandre Scarlet - avatar
+ 5
Mert Yazıcı thanks, what's the 2nd argument🤔
24th Dec 2018, 2:00 PM
Flandre Scarlet
Flandre Scarlet - avatar
+ 2
I guess this is what you want but it can be much simpler https://code.sololearn.com/c8UxT7X1aX64
8th Sep 2018, 7:41 PM
Flandre Scarlet
Flandre Scarlet - avatar
+ 2
Ulisses Cruz Its in the name of the code
8th Sep 2018, 8:08 PM
I Am Arthur
I Am Arthur - avatar
+ 2
Cépagrave How this works?What "*" do?
8th Sep 2018, 8:09 PM
I Am Arthur
I Am Arthur - avatar
+ 2
Cépagrave And the zip?
9th Sep 2018, 3:12 AM
I Am Arthur
I Am Arthur - avatar
+ 2
Thx Cepagrave! I check it) print([1,2,3]) print(*[1,2,3]) print(type(*[1,2])) # why bug?
24th Dec 2018, 4:30 AM
Vitalij Bredun ♡ Python Petersburg
Vitalij Bredun ♡ Python Petersburg - avatar
0
what are you trying to do?
8th Sep 2018, 1:39 PM
Ulisses Cruz
Ulisses Cruz - avatar