Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - iterating through a list of integers

I have a dictionary containing keys that have values containing values such as "13896615011", "330405011", and some can contain multiple value like so: (3012292011, 1292123011)

I am running through a list of possible keys, where i say:

for x in list: 
   if (x in dict):
      found_match = dict.get(x)
      print(found_match)

And this gives me these values:

[13896615011]

[330405011]

[3012292011, 1292123011]

[2476681011]

[172450, 3109930011]

and so on.

Now, I have another dictionary that uses the values printed out above as keys, but when I use a for loop to read through each value, it gives me each integer separately like so:

for value in found_match:
   print(value)

And it would return, for the first value,

1

3

8

9

and so on, for all values in the list. The reason I want to iterate through found_match is because there can be two values and not just one. I want to append all the possible values returned from my second dictionary that uses the values (e.g 13896615011) as keys- so I can map the values to my first dictionary's original key.

How can I achieve this?

like image 486
Shaun Tan Avatar asked Apr 12 '26 01:04

Shaun Tan


1 Answers

I think this is what you want

found_match=[]
for x in list: 
   if (x in dict):
      found_match.append(dict.get(x))
      print(found_match)
like image 75
Daniyal Syed Avatar answered Apr 14 '26 14:04

Daniyal Syed