On Wed, 25 Apr 2001, mary wrote: > Well I found the answer to my previous post (in the excellent > 'Essential Python Reference' book by David M Beazley - highly recommended), > but now I have a follow-up question. > > I can use 'map(None, a, b, c)' to take 'vertical slices out of tuples a, b > and c. Oh yeah -- I forgot about that special case. > I want to generalise this to a dictionary of tuples. I'm a bit stuck on > how to call map with a varying number of arguments, ie: > > Here's a program which works as desired, but is not generalised: [...] > z = map(None, x[y[0]], x[y[1]], x[y[2]]) <---How do I > generalise this call?... [...] map() is a function, and you can call functions using apply(): func(arg0, arg1, arg2...) <--> apply(func, (arg0, arg1, arg2...)) so make a sequence, seq, of your x[y[i]] terms, eg. seq = [x[y[i]] for i in range(3)] and apply it to map(): z = apply(map, seq) John
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4