I understand that with one argument, the list map()can be replaced by a list comprehension. for instance
map()
map(lambda x : x**2, range(5))
can be replaced by
[x**2 for x in range(5)]
Now, how would I do something similar for two parallel lists. In other words, I have a line of code with the following pattern:
map(func, xs, ys)
where func()takes two arguments.
func()
How can I do the same with the list?
map() zip() function . zip() , :
zip()
[func(x, y) for x, y in zip(xs, ys)]
, map(func, a1, a2, .., an) [func(*args) for args in zip(a1, a2, .., an)].
map(func, a1, a2, .., an)
[func(*args) for args in zip(a1, a2, .., an)]
Source: https://habr.com/ru/post/1664872/More articles:Воспроизводимые случайные значения в векторе произвольной длины - randomPerl: checking that the file ** is actually ** writable, as opposed to checking file permissions - perlReplace a hard-coded list of numbers with dynamic array length - javascriptJava and Box2D - Which body should be considered as a bullet? - javaMarine graphics in a loop - pythonImplementing various layouts for (part of) a web page - javascriptMongoDB moves cursor too slowly - performancereport-native start report: Error: UNKNOWN: unknown error, open ... \. babel.json - react-nativeFlex: select the first and last item on each line in a wrapped flex - htmlPymongo cursor iteration alternative - pythonAll Articles