I have two lists xscat and yscat. I would like the list comprehension to pick up x and y in xscat and yscat respectively. Resulting list should contain peaks([x[0], y[0]]), peaks([x[1], y[1]])
, etc
xscat=yscat=[-1, -1.5,5] [peaks([x,y]) for x,y in xscat,yscat]
Can you find any solution using comprehensions ? or other ways to put it (map)?
The map() function is a built-in function in Python, which applies a given function to each item of iterable (like list, tuple etc) and returns a list of results or map object. Note : You can pass as many iterable as you like to map() function.
You can send any data types of argument to a function (string, number, list, dictionary etc.), and it will be treated as the same data type inside the function.
Functions can accept more than one argument. When calling a function, you're able to pass multiple arguments to the function; each argument gets stored in a separate parameter and used as a discrete variable within the function. This video doesn't have any notes.
zip
is what you want:
[peaks([x,y]) for x,y in zip(xscat,yscat)]
You need to use zip
:
[peaks([x,y]) for (x,y) in zip(xscat, yscat)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With