简体   繁体   English

元组字典的列表理解

[英]List comprehension on dictionary of tuples

Is it possible to this as a list comprehension? 有可能作为列表理解吗?

points = []
for partial in partials:
    for point in partials[partial]:
        if point[0] == time:
            points.append(partial)

in python3? 在python3中?

Thanks, 谢谢,

Barry 巴里

Yes. 是。

points = [partial
          for partial in partials
          for point in partials[partial]
          if point[0] == time]

(Not sure what this is useful for, but at least this will do the same as your original code.) (不知道这对您有什么用,但是至少这样做与您的原始代码相同。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM