Creating a new dictionary from a dictionary with multiple values per key -


i have dictionary looks basically

d = {'book1': [('chapverse1', 'verse1'),('chapverse2','verse2')]      'book2': [('chapverse1', 'verse1'),('chapverse2','verse2')]} 

what need create second dictionary values inside based on book in. like:

read through d if book in d 

create newdict values book.

any appreciated. in python 2.7

well it's unclear want do, i'll try guess:

>>> d = {       'book1': [('chapverse1', 'verse1'),('chapverse2','verse2')],       'book2': [('chapverse1', 'verse1'),('chapverse2','verse2')]     } >>> d2 = {k: dict(v) k, v in d.items()} >>> d2 {     'book1': {'chapverse1': 'verse1', 'chapverse2': 'verse2'},     'book2': {'chapverse1': 'verse1', 'chapverse2': 'verse2'} } 

edit:

>>> book = 'book2' >>> book_dict = dict(d['book2']) >>> book_dict {'chapverse1': 'verse1', 'chapverse2': 'verse2'} 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -