Nov-09-2021, 01:16 PM
Thanks for the help, I'm nearly there.... hopefully: now I have the code below that works and gives the last value of the list as you said. Then I tried to use "append" in order to have all the values (or names) and from my understanding I should append the output of each iteration inside the loop, but still get error "'float' object has no attribute 'append'", as per the below code. So how can I append each output from the for loop to the previous one in order to get the desired results in one line, e.g. [19.75, 20.06, 17.94, 18.77, 20.34]?
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] y.append(x) return y data = list_1 get_data(list_1,'length') output = get_data(list_1, 'length') print(output, end=" ")