List comprehension without [ ] in Python

后端 未结 7 2256
悲&欢浪女
悲&欢浪女 2020-11-21 05:28

Joining a list:

>>> \'\'.join([ str(_) for _ in xrange(10) ])
\'0123456789\'

join must take an iterable.

Appa

7条回答
  •  醉话见心
    2020-11-21 05:38

    As mentioned it's a generator expression.

    From the documentation:

    The parentheses can be omitted on calls with only one argument. See section Calls for the detail.

提交回复
热议问题