[Tutor] creating dictionary from a list

Saad Bin Javed sbjaved at gmail.com
Sat Apr 13 06:00:26 CEST 2013


Thank you Steven! I followed your tips and came up with this:

lst = filter(None, lst)
lst = [item.split('  ', 1) for item in lst]
lst = [item for sublist in lst for item in sublist]
lst = filter(None, lst)

dict = {}
for item in lst:
	if item.startswith(('Mon','Tue','Wed','Thu','Fri','Sat','Sun')):
		
		dict.update({lst[lst.index(item)].lstrip(): 
lst[lst.index(item)+1].lstrip()})
print dict

The program lines have halved :)


More information about the Tutor mailing list