# for demonstration, I am using random number generator
import tkinter as tk
import random
measure_status = True
def readValues():
if measure_status :
outputs = [0]*0
outputs.append(rand.randrange(0,100,1))
outputs.append(rand.randrange(0,100,1))
outputs.append(rand.randrange(0,100,1))
outputs.append(rand.randrange(0,100,1))
# do i need another variable to save all the list to compare
win.after(1000, readValues)
def calc_max():
global measure_status
measure_status = False #stopping meaasurement.
# rest of the code here? how to compare lists?
win = Tk()
calc_btn = tk.Button(win, text = "Calculate", command=calc_max )
calc_btn.grid(row=4, column=4)
win.after(1000, readValues)
win.mainloop()
答案 0 :(得分:2)
您可以使用zip
和max
:
def get_max_list(list_of_lists):
"""
Returns a list of max values for the zips of list_of_lists.
Assumes each list is the same length.
"""
return [max(x) for x in zip(*list_of_lists)]
# The above is equivalent to:
# result = []
# for x in zip(l1, l2, l3):
# result.append(max(x))
# print(*result) # Just prints each entry in result.
l1 = [10, 5, 23, 24]
l2 = [22, 35, 45, 12]
l3 = [0, 22, 123, 33]
lists = [l1, l2, l3] # our list of lists example input
print(*get_max_list(lists))
输出:
22 35 123 33