Python 3 filter - Bug or Feature?

前端 未结 2 1494
梦毁少年i
梦毁少年i 2021-01-27 08:41

Okay, I am a complete newbie to Python - and stackoverflow. I am coming from a ksh and Perl background.

The following in an interactive session with Python 2.7:

2条回答
  •  隐瞒了意图╮
    2021-01-27 09:18

    Note that you don't usually need a list of values. You can directly loop the output like below

    for value in VALIDVALUES:
      do_some_thing(value)
    

    or

    for value in filter(...):
      do_some_thing(value)
    

    Sometimes you may need unique values or non mutable values. Use set or tuple or frozenset instead of list as shown in the other answer.

提交回复
热议问题