A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/094411.html below:

followup: vertical slices from a matrix in a dictionary?...

followup: vertical slices from a matrix in a dictionary?...John J. Lee phrxy at csv.warwick.ac.uk
Wed Apr 25 11:27:39 EDT 2001
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


More information about the Python-list mailing list

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