52882/convert-list-into-dict-in-python
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
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)
You can use the ast module Ex: import ast s = """[{'10': ...READ MORE
You could try using the AST module. ...READ MORE
Hi@akhtar You can convert a dictionary dataset into ...READ MORE
suppose you have a string with a ...READ MORE
You can also use the random library's ...READ MORE
Syntax : list. count(value) Code: colors = ['red', 'green', ...READ MORE
Enumerate() method adds a counter to an ...READ MORE
Here's a generator that yields the chunks ...READ MORE
with open(fname) as f: content = f.readlines() # you ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.