我正在尝试对这段代码做一个更优雅的版本。这基本上只是根据数字将一个字符串附加到 categorynumber 。将不胜感激任何帮助。
number = [100,150,200,500]
categoryNumber = []
for i in range (0,len(number)):
if (number [i] >=1000):
categoryNumber.append('number > 1000')
elif (number [i] >=200):
categoryNumber.append('200 < number < 300')
elif (number [i] >=100):
categoryNumber.append('100 < number < 200')
elif (number [i] >=50):
categoryNumber.append('50 < number < 100')
elif (number [i] < 50):
categoryNumber.append('number < 50')
for i in range(0,len(categoryNumber)):
print i