How to Convert Nested List into dictionary in Python where lst[0][0] is the key -


please help! have python (3x) nested list looks following:

lst = [['kataba', 'v:', '3rd_sg_masc_perf_active'], ['kataba:', 'v:', '3rd_dual_masc_perf_active'], ['katabu:', 'v:', '3rd_pl_masc_perf_active'], ['katabat', 'v:', '3rd_sg_fm_perf_active'], ['katabata:', 'v:', '3rd_dual_fm_perf_active']] 

i slice 1 instance question clearer

>>> lst[0] ['kataba', 'v:', '3rd_sg_masc_perf_active'] >>> lst[0][0] 'kataba' >>> lst[0][1:] ['v:', '3rd_sg_masc_perf_active'] 

the question is: how convert above nested list dictionary where, example, lst[0][0] dictionary key, , lst[0][1:] value of key.

this nested list contains tens of thousands of elements.

could me, because have tried many options seems don't have logic it.

thank in advance kind , attention!

if understand correctly, think you're after following.

you can use dict-comp versions 2.7+:

{ k[0]: k[1:] k in lst } 

prior 2.7 (2.6 , below), have been done using dict builtin, eg:

dict( (k[0], k[1:]) k in lst) # {'kataba': ['v:', '3rd_sg_masc_perf_active'], 'katabat': ['v:', '3rd_sg_fm_perf_active'], 'katabata:': ['v:', '3rd_dual_fm_perf_active'], 'katabu:': ['v:', '3rd_pl_masc_perf_active'], 'kataba:': ['v:', '3rd_dual_masc_perf_active']} 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -