1
2
3
4
5
6
7
8
9
10
|
>>> a = range(
0
,
5
)
>>> b = range(
5
,
10
)
>>> a
[
0
,
1
,
2
,
3
,
4
]
>>> b
[
5
,
6
,
7
,
8
,
9
]
>>> zip(a,b)
[(
0
,
5
), (
1
,
6
), (
2
,
7
), (
3
,
8
), (
4
,
9
)]
>>> zip(b,a)
[(
5
,
0
), (
6
,
1
), (
7
,
2
), (
8
,
3
), (
9
,
4
)]
|
1
2
3
4
5
6
7
8
|
>>> a = range(
1
,
5
)
>>> b = [
'a'
,
'b'
,
'c'
]
>>> a
[
1
,
2
,
3
,
4
]
>>> b
[
'a'
,
'b'
,
'c'
]
>>> zip(a,b)
[(
1
,
'a'
), (
2
,
'b'
), (
3
,
'c'
)]
|
1
2
3
4
5
6
7
|
>>> key = [
'name'
,
'girlfriend'
]
>>> values = [
'xpleaf'
,
'CL'
]
>>> zip(key, values)
[(
'name'
,
'xpleaf'
), (
'girlfriend'
,
'CL'
)]
>>> dict(zip(key, values))
{
'girlfriend'
:
'CL'
,
'name'
:
'xpleaf'
}
>>> dict(zip(key, values))
|
1
2
3
4
5
6
7
8
|
>>> a = range(
1
,
5
)
>>> b = [
'a'
,
'b'
,
'c'
,
'd'
]
>>> map(a,b)
Traceback (most recent call last):
File
"<stdin>"
, line
1
,
in
<module>
TypeError:
'list'
object
is
not callable
>>> map(None,a,b)
[(
1
,
'a'
), (
2
,
'b'
), (
3
,
'c'
), (
4
,
'd'
)]
|
1
2
3
4
|
>>> b.pop()
'd'
>>> map(None, a, b)
[(
1
,
'a'
), (
2
,
'b'
), (
3
,
'c'
), (
4
, None)]
|