开发者

Suggestions for improving this little piece of code?

开发者 https://www.devze.com 2023-01-24 16:54 出处:网络
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

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] 
0

精彩评论

暂无评论...
验证码 换一张
取 消