Re: Zipping a dictionary whose values are lists

2012-04-12 Thread Pavel Anossov
zip(*d.values())

On 12 April 2012 20:28,   wrote:
> I using Python 3.2 and have a dictionary
 d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]}
>
> whose values are lists I would like to zip into a list of tuples. If I 
> explicitly write:
 list(zip([1,2], [1,2,3], [1,2,3,4])
> [(1, 1, 1), (2, 2, 2)]
>
> I get exactly what I want. On the other hand, I have tried
>
list(zip(d))
> [(0,), (1,), (2,)]
>
 list(zip(d.values()))
> [([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]
>
 list(zip(d[i] for i in d))
> [([1, 2],), ([1, 2, 3],), ([1, 2, 3, 4],)]
>
 list(zip(*d))
> Traceback (most recent call last):
>  File "", line 1, in 
>    list(zip(*d))
> TypeError: zip argument #1 must support iteration
>
> and nothing quite works. What am I doing wrong?
>
> Sincerely
>
> Thomas Philips
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
С уважением, Аносов Павел
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how many days in one year ?

2012-04-22 Thread Pavel Anossov
import calendar

print 366 if calendar.isleap(2003) else 365



On 22 April 2012 13:37, contro opinion  wrote:
> i want to know how many days in one year,
> import time
> import datetime
> d1= datetime.datetime(2003, 1, 1)
> d2=datetime.datetime(2003, 21, 31)
> print  (d2-d1).days+1
>
> i can get there are 365 days in the 2003,
>
> is there other way,better way  to calculate  ?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
С уважением, Аносов Павел
-- 
http://mail.python.org/mailman/listinfo/python-list