Python 3 Map function is not Calling up function

前端 未结 3 855
南旧
南旧 2020-12-03 06:49

Why doesn\'t following code print anything:

#!/usr/bin/python3
class test:
    def do_someting(self,value):
        print(value)
        return value

    de         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 07:42

    I just want to add the following:

    With multiple iterables, the iterator stops when the shortest iterable is exhausted [ https://docs.python.org/3.4/library/functions.html#map ]

    Python 2.7.6 (default, Mar 22 2014, 22:59:56)

    >>> list(map(lambda a, b: [a, b], [1, 2, 3], ['a', 'b']))
    [[1, 'a'], [2, 'b'], [3, None]]
    

    Python 3.4.0 (default, Apr 11 2014, 13:05:11)

    >>> list(map(lambda a, b: [a, b], [1, 2, 3], ['a', 'b']))
    [[1, 'a'], [2, 'b']]
    

    That difference makes the answer about simple wrapping with list(...) not completely correct

    The same could be achieved with:

    >>> import itertools
    >>> [[a, b] for a, b in itertools.zip_longest([1, 2, 3], ['a', 'b'])]
    [[1, 'a'], [2, 'b'], [3, None]]
    

提交回复
热议问题