Python lambda怎么写?
发布网友
发布时间:2022-04-24 13:13
我来回答
共1个回答
热心网友
时间:2022-05-07 04:36
tim@crunchbang:~$ python
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> wordsList = ['cat', 'elephant', 'rat', 'rat', 'cat']
>>> result = map(lambda x: (x,1), wordsList)
>>> result
[('cat', 1), ('elephant', 1), ('rat', 1), ('rat', 1), ('cat', 1)]
>>>