Chinese In North America(北美华人e网)

注册
发新话题 回复该主题

1#

CSE 115 python 问题


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


怎么就不对了呢
TOP
分享到微信 分享到Facebook 分享到Twitter 分享到新浪微博 复制到剪贴板
agree
0
disagree
0
2#

不对的东西太多了,楼主是不是刚刚开始学编程啊?
TOP
agree
0
disagree
0
3#

回复 2楼woshime的帖子

对,
TOP
agree
0
disagree
0
4#

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

这样还是不对。。。。。。。。。。。。。。。。。。。。。
TOP
agree
0
disagree
0
5#

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
最后编辑woshime 最后编辑于 2019-10-09 21:33:14
TOP
agree
0
disagree
0
6#

回复 5楼woshime的帖子

谢谢,
TOP
agree
0
disagree
0
发新话题 回复该主题