1

I want to generate all the values in a dictionary to a list.

a={'alpha':1.2,'beta':0.5}

Here I want the output as:

[1.2,0.5]
ls=[]
for i in a.items():

    for j in i:

        if j==int:

            ls.append(j)

Output as

[1.2,0.5]
Emma
  • 27,428
  • 11
  • 44
  • 69

2 Answers2

-1

Try this ,may help

a={'alpha':1.2,'beta':0.5}
ls=[]
for it in a.values():
    ls.append(it)
-1

try this code, similar to yours

ls=[]

for i in a.items():
    ls.append(i[1])
print(ls)

best, giulio

giulio
  • 157
  • 8