-3
source = [{'address': 15620, 'street': 490}, {'address': 10180, 'street': 2187}, {'address': 10190, 'street': 670}, {'address': 20900, 'street': 572}, {'address': 8190, 'street': 1103}, {'address': 43110, 'street': 225}, {'address': 24780, 'street': 1465}, {'address': 50130, 'street': 249},]

I want to make a list like this. Please help me. Thanks.

result = (15620, 10180, 10190, 20900, 8190, 43110, 24780, 50130)
dmz0004
  • 1
  • 2

2 Answers2

5

You can use a list comprehension to get the 'address' key from each dictionary in your source list:

result = [ d['address'] for d in source ]
Alain T.
  • 40,517
  • 4
  • 31
  • 51
0

You can do it like below using get()

k=[]
for i in source:
    k.append(i.get("address", ""))

k will give you the output you are looking for.

Heenashree Khandelwal
  • 659
  • 1
  • 13
  • 30