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
#7
(Sorry Larz, we were almost at the same time answering.)

Very well, you are making progress. But you should be more precise than saying: " but didn't work as well". You get the following message, right?
Error:
Traceback (most recent call last): File "/home/ibreeden/PycharmProjects/Forum/venv/impos01.py", line 23, in <module> output = get_data(data, key) NameError: name 'key' is not defined
It is because you write:
get_data(list_1,'length')
output = get_data(data,key)
Replace that with:
output = get_data(list_1, 'length')
Output:
19.75
Now this is still not what you want, because this is only the first occurence.
In the function get_data() you have a return in the for-loop. That is wrong. You must return after the loop has finished. So unindent the return statement.
Output:
20.34
Still not what you want, now it shows only the last occurrence. Have a look at the list "y = []". Do you know how to append() values to a list?
Paulman likes this post
Reply


Messages In This Thread
RE: function for extracting data from lists - by ibreeden - Nov-09-2021, 11:01 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