punit
asked on
Python list of tuples
Hi,
I have a list of tuples and would like to create a list as described below:
Given list of tuples:
[(datetime.datetime(2008, 6, 21, 0, 0), 26, 'A'),
(datetime.datetime(2008, 6, 22, 0, 0), 22, 'B'),
(datetime.datetime(2008, 6, 22, 0, 0), 15, 'C'),
(datetime.datetime(2008, 6, 22, 0, 0), 16, 'A'),
(datetime.datetime(2008, 6, 23, 0, 0), 17, 'A'),
(datetime.datetime(2008, 6, 23, 0, 0), 0, 'B'),
(datetime.datetime(2008, 6, 23, 0, 0), 14, 'C')]
Resulted list required:
Dates=[datetime.datetime(2 008, 6, 21, 0, 0),datetime.datetime(2008, 6, 22, 0, 0),datetime.datetime(2008, 6, 23, 0, 0)]
A=[26,16,17]
B=[0,22,0]
c=[0,15,14]
Here we are constructing list for DATES, A,B & C.As you can see in resulted list for A,B,C, it put 0 if there is no data for given date. I am not sure how I can achieve these resulted list for Dates,A,B,C.
Thanks,
I have a list of tuples and would like to create a list as described below:
Given list of tuples:
[(datetime.datetime(2008, 6, 21, 0, 0), 26, 'A'),
(datetime.datetime(2008, 6, 22, 0, 0), 22, 'B'),
(datetime.datetime(2008, 6, 22, 0, 0), 15, 'C'),
(datetime.datetime(2008, 6, 22, 0, 0), 16, 'A'),
(datetime.datetime(2008, 6, 23, 0, 0), 17, 'A'),
(datetime.datetime(2008, 6, 23, 0, 0), 0, 'B'),
(datetime.datetime(2008, 6, 23, 0, 0), 14, 'C')]
Resulted list required:
Dates=[datetime.datetime(2
A=[26,16,17]
B=[0,22,0]
c=[0,15,14]
Here we are constructing list for DATES, A,B & C.As you can see in resulted list for A,B,C, it put 0 if there is no data for given date. I am not sure how I can achieve these resulted list for Dates,A,B,C.
Thanks,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On the other hand, it may be rather difficult to understand to a beginner.