0
Please help me friends how to get a dictionary (d) from the list(l1).can we do it by dictionary comprehenson???
Input l1=[1,5,22,9,999,55,1000] Output d={1:[1,5,9],2:[22,55],3:999,4:1000}
15 Answers
+ 1
Another way to do this
https://code.sololearn.com/cWH1dmmVSBdv/?ref=app
+ 2
d = {i: [n for n in arr if len(str(n)) == i] for i in range(1, max([len(str(n)) for n in arr])+1)}
+ 1
Key is number of digits
Value is corresponding number from the list. Eg. d[1]=[1,5,9] ,d[2]=[22,55], d [3]=999,d[4]=1000
+ 1
This code is smart. Thank you Ipang !!!
+ 1
Your code is working great.
Thank you HonFu .
0
AttributeError. int object has no attribute append
0
Bagon it's throw an error
0
Thanks a lot for your help Bagon
0
No problem JMVENKATESAN đ