CSE 115 python 问题

T
Tian0924
楼主 (北美华人网)
filterInRange Define a function named filterInRange with four parameters. The first argument passed to the function should be a list of dictionaries (the data), the second a string (a dictionary key), with the third and fourth arguments being numbers, representing the low and high values of range. This function must return a list of all the dictionaries from the input list which contain the key:value pairs where low <= value < high.
Sample function call: filterInRange(data,'value', 0, 8000)
def filterInRange(data,k,l,h):
y=[]
for s in data:
for w in s.values():
if w<h and w>=l:
y.append(s)
return y

怎么就不对了呢
w
woshime
不对的东西太多了,楼主是不是刚刚开始学编程啊?
T
Tian0924
回复 2楼woshime的帖子 对,
T
Tian0924
def filterInRange(data,k,l,h): y=[] for key in data: v=key.values() if v<=h and v>=l: y.append(v) return y 这样还是不对。。。。。。。。。。。。。。。。。。。。。
w
woshime
def filterInRange(data,k,l,h): y=[] for a in data: If a.key()==k: v=a.values() if v>=l and v<h: # <h not <=h y.append(a) return y
T
Tian0924
回复 5楼woshime的帖子 谢谢,