Iterator (iter()) function in Python.

前端 未结 2 1202
独厮守ぢ
独厮守ぢ 2021-02-05 10:31

For dictionary, I can use iter() for iterating over keys of the dictionary.

y = {\"x\":10, \"y\":20}
for val in iter(y):
    print val
2条回答
  •  渐次进展
    2021-02-05 11:14

    All of these work fine, except for a typo--you probably mean:

    x = Counter(3,8)
    for i in x:
        print i
    

    rather than

    x = Counter(3,8)
    for i in x:
        print x
    

提交回复
热议问题