Convert list into dict in Python

0 votes
li = [[1234,"BOND1","GROUP1"],
[1235,"BOND1","GROUP2"],
[1236,"BOND2","GROUP1"],
[1237,"BOND3","GROUP1"],
[1246,"BOND3","GROUP2"],
[1256,"BOND1","GROUP1"],
[1290,"BOND2","GROUP2"]
]

How can I convert it into dict

Jul 24 in Python by Kunal
25 views

1 answer to this question.

0 votes

Try using the below-mentioned code, it should work:

new=dict()

for i in range(len(li)):

    new[li[i][0]]=li[i][1:]

print(new)

answered Jul 24 by Banu

Related Questions In Python

0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 56,920 points
596 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 56,920 points
72 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
788 views
+1 vote
2 answers

How can I remove duplicate dict in list in Python?

[dict(t) for t in {tuple(d.items()) for d ...READ MORE

answered Aug 15 in Python by anonymous

edited Aug 20 by Kalgi 1,595 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 344 views
+4 votes
7 answers

Splitting a List into chunks in Python

Here's a generator that yields the chunks ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
7,523 views
0 votes
1 answer

In Python, how do I read a file line-by-line into a list?

with open(fname) as f:     content = f.readlines() # you ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,180 points
136 views