I am trying to create a list of tuples in django like
appointments = [(datetime(2012, 5, 22, 10), datetime(2012, 5, 22, 10, 30)),
(datetime(2012, 5, 22, 12), datetime(2012, 5, 22, 13)),
(datetime(2012, 5, 22, 15, 30), datetime(2012, 5, 22, 17, 10))]
I am iterating a django query set and storing the value in appoinments list like
appoinments = []
for select_meeting in get_meeting:
getm = int(select_meeting.duration)
appoinments += zip(((select_meeting.meeting_datetime),
(select_meeting.meeting_datetime + timedelta(minutes = getm))))
print appoinments
But it’s returning the result like that’s not my requirement actually
[(datetime.datetime(2012, 11, 11, 21, 5),),
(datetime.datetime(2012, 11, 11, 22, 5),),
(datetime.datetime(2012, 11, 11, 23, 5),),
(datetime.datetime(2012, 11, 12, 0, 5),)]
You are using zip wrong – it is actually how it works and that’s normal (i-th tuple it returns contains i-th element of given iterable).
Those line should be:
and it should be what you want now.