Any suggestions to improve this little piece of code? It works, but there must be a better way of doing it. Especially the first two lines, I have a bunch of them. Can't 开发者_JS百科I merge the two somehow?
for iso in set(BAR_Items):
if iso+YEAR in heights:
mylist.append(heights[iso+YEAR])
mylist.sort()
cut = percentile(mylist, POS)
Thanks
The first three lines can be written concisely as a list comprehension.
mylist += [heights[iso+YEAR] for iso in set(BAR_Items) if iso+YEAR in heights]
精彩评论