|
发表于 2022-8-8 16:15:18
|
显示全部楼层
years=[1997,1998,1999,2000]
enumerate(years)
<enumerate object at 0x10b9febc0>
list(enumerate(years))
[(0, 1997), (1, 1998), (2, 1999), (3, 2000)]
list(enumerate(years),100)
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
list(enumerate(years),100)
TypeError: list expected at most 1 argument, got 2
list(enumerate(years),100))
SyntaxError: unmatched ')'
list((enumerate(years),100))
[<enumerate object at 0x10ab08600>, 100]
list((enumerate(years),100))
[<enumerate object at 0x10a90cdc0>, 100]
list(enumerate(years,100))
[(100, 1997), (101, 1998), (102, 1999), (103, 2000)]
list(enumerate(years))
[(0, 1997), (1, 1998), (2, 1999), (3, 2000)]
a=[1,2,3]
b=[4,5,6]
zipped=zip(a,b)
zipped
<zip object at 0x10bca5040>
list(zipped)
[(1, 4), (2, 5), (3, 6)]
c=[7,8,9]
zipped=zip(a,b,c)
list(zipped)
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
z='ctxhs'
zipped=zip(a,b,z)
listed(zipped)
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
listed(zipped)
NameError: name 'listed' is not defined. Did you mean: 'list'?
list(zipped)
[(1, 4, 'c'), (2, 5, 't'), (3, 6, 'x')]
import itertools
zipped=itertools._longest(a,b,z)
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
zipped=itertools._longest(a,b,z)
AttributeError: module 'itertools' has no attribute '_longest'. Did you mean: 'zip_longest'?
zipped=itertools.zip_longest(a,b,z)
list(zipped)
[(1, 4, 'c'), (2, 5, 't'), (3, 6, 'x'), (None, None, 'h'), (None, None, 's')]
mapped=map(pow,[2,5,8],[3,6,9])
list(mapped)
[8, 15625, 134217728]
mapped=(min,[2,6,656],[23,43,1][3,532,22])
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
mapped=(min,[2,6,656],[23,43,1][3,532,22])
TypeError: list indices must be integers or slices, not tuple
mapped=(map(min,[2,6,656],[23,43,1][3,532,22]))
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
mapped=(map(min,[2,6,656],[23,43,1][3,532,22]))
TypeError: list indices must be integers or slices, not tuple
list(map(min,[2,6,656],[23,43,1][3,532,22,00]))
Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
list(map(min,[2,6,656],[23,43,1][3,532,22,00]))
TypeError: list indices must be integers or slices, not tuple
list(map(min,[2,6,656],[23,43,1][3532,22,00]))
Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
list(map(min,[2,6,656],[23,43,1][3532,22,00]))
TypeError: list indices must be integers or slices, not tuple
list(map(min,[2,6,656],[23,43,1][3532,22,200]))
Traceback (most recent call last):
File "<pyshell#37>", line 1, in <module>
list(map(min,[2,6,656],[23,43,1][3532,22,200]))
TypeError: list indices must be integers or slices, not tuple
list(map(max,[2,6,56],[23,43,1][532,22,200]))
Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
list(map(max,[2,6,56],[23,43,1][532,22,200]))
TypeError: list indices must be integers or slices, not tuple
list(map(max,[1,3,5],[2,2,2][0,3,9,8]))
Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
list(map(max,[1,3,5],[2,2,2][0,3,9,8]))
TypeError: list indices must be integers or slices, not tuple
>>> list(map(max, [1, 3, 5], [2, 2, 2], [0, 3, 9, 8]))
SyntaxError: invalid syntax
list(map(max, [1, 3, 5], [2, 2, 2], [0, 3, 9, 8]))
[2, 3, 9]
list(map(max,[1,3,5],[2,2,2][0,3,9,8]))
Traceback (most recent call last):
File "<pyshell#42>", line 1, in <module>
list(map(max,[1,3,5],[2,2,2][0,3,9,8]))
TypeError: list indices must be integers or slices, not tuple
list(map(max, [1,3,5], [2,2,2], [0,3,9,8]))
[2, 3, 9]
list(map(max,[1,3,5],[2,2,2][0,3,9,8]))
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
list(map(max,[1,3,5],[2,2,2][0,3,9,8]))
TypeError: list indices must be integers or slices, not tuple
list(map(max, [2,6,56], [23,43,1], [532,22,200]))
[532, 43, 200]
list(map(min, [2,6,56], [23,43,1], [532,22,200]))
[2, 6, 1]
filter(str.isupper, "CtXHss")
<filter object at 0x10bcebaf0>
li(filter)
Traceback (most recent call last):
File "<pyshell#48>", line 1, in <module>
li(filter)
NameError: name 'li' is not defined
list(filter)
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
list(filter)
TypeError: 'type' object is not iterable
list(filter(str.isupper, "CtXHss"))
['C', 'X', 'H']
mapped=map(ord,'ctx')
for each in mapped:
print(each)
99
116
120
list(mapped)
[]
x=[1,2,3]
y=iter(x)
type(x)
<class 'list'>
type(y)
<class 'list_iterator'>
next(y)
1
next(y)
2
next(y)
3
next(y)
Traceback (most recent call last):
File "<pyshell#63>", line 1, in <module>
next(y)
StopIteration
z=iter(x)
next(z,'被掏空了')
SyntaxError: invalid character ')' (U+FF09)
next(z,'被掏空了')
1
next(z,'被掏空了')
2
next(z,'被掏空了')
3
next(z,'被掏空了')
'被掏空了' |
|