[Tutor] Python and Tuples

bob gailer bgailer at gmail.com
Sun Jan 30 19:54:09 CET 2011


On 1/30/2011 4:29 AM, Becky Mcquilling wrote:
> I'm fairly new to python and I am trying to do some math with tuples.
>
> If I have a tuple:
>
> t =( (1000, 2000), (2, 4), (25, 2))
> I want to loop through and print out the results of the multiplying 
> the two numbers like so:
>
> 1000 x 2000
> 2 x 4

The one-line version:

print [x*y for x,y in t]

or even better, in Python 3.x

[print(x*y) for x,y in t]

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list