Python Forum
function for extracting data from lists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function for extracting data from lists
#5
OK thanks, then my understanding from your comment is the below, but didn't work as well:

def main(list_1):
    return main
 
list_1 = [
    {'name': 'Jerome', 'weight': 3.38, 'wingspan': 49.96, 'length': 19.75},
    {'name': 'Ibraheem', 'weight': 3.08, 'wingspan': 50.59, 'length': 20.6},
    {'name': 'Tiana', 'weight': 0.81, 'wingspan': 47.86, 'length': 17.94},
    {'name': 'Lucas', 'weight': 3.33, 'wingspan': 48.27, 'length': 18.77},
    {'name': 'Rickie', 'weight': 4.4, 'wingspan': 51.0, 'length': 20.34}
]
 
def get_data(data,key):
    y = []
    for x in data:
      y=x[key]
      return y
data = list_1
get_data(list_1,'length')
output = get_data(data,key)
print(output, end=" ")
Reply


Messages In This Thread
RE: function for extracting data from lists - by Paulman - Nov-09-2021, 10:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Recursive Function - Compare 2 lists, return the elements that don't exist in both KellyBaptist 1 6,321 Dec-23-2018, 10:10 AM
Last Post: Gribouillis
  Questions on lists, the range function & concatenation fad3r 7 5,725 Jan-25-2018, 03:11 PM
Last Post: fad3r
  How to extract two data types from a text file and store them as two separate lists banf 1 4,068 Jan-16-2017, 09:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020