+ 7
Help (python)
Can someone help me with this code https://code.sololearn.com/c7NYBwzZ18lV/?ref=app
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)
+ 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(...)).
+ 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)]
+ 8
a, b = list(map(lambda x: list(map(int, x)),[a,b]))
+ 8
bases.
class A(B, C):
pass
type('A', (B, C), {})
+ 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)
+ 5
Vitalij Bredun ♡ JUMP_LINK__&&__Python__&&__JUMP_LINK Petersburg type() only accept one argument
+ 5
Mert Yazıcı thanks, what's the 2nd argument🤔
+ 2
I guess this is what you want
but it can be much simpler
https://code.sololearn.com/c8UxT7X1aX64
+ 2
Ulisses Cruz Its in the name of the code
+ 2
Cépagrave How this works?What "*" do?
+ 2
Cépagrave And the zip?
+ 2
Thx Cepagrave!
I check it)
print([1,2,3])
print(*[1,2,3])
print(type(*[1,2])) # why bug?
0
what are you trying to do?