我想了解爲什麼在Python 3中對zip
對象使用排序函數不能多做一次。它只是第二次返回空列表。蟒蛇重複排序3
In [34]: X = ["a", "b", "c", "d", "e", "f", "g", "h", "i"]
...: Y = [ 0, 1, 1, 0, 1, 2, 2, 0, 1]
...: yx = zip(Y, X)
...: yx
...: [(0, 'a'), (1, 'b'), (1, 'c'), (0, 'd'), (1, 'e'), (2, 'f'), (2, 'g'),
...: (0, 'h'), (1, 'i')]
...: yx_sorted=sorted(yx)
...:
In [35]: yx_sorted
Out[35]:
[(0, 'a'),
(0, 'd'),
(0, 'h'),
(1, 'b'),
(1, 'c'),
(1, 'e'),
(1, 'i'),
(2, 'f'),
(2, 'g')]
In [36]: yx_sorted=sorted(yx)
In [37]: yx_sorted
Out[37]: []
In [38]: yx
Out[38]: <zip at 0x10476aa88>
yx
仍然存在,據我所知。
@StefanPochmann同意並完成。 –
感謝您的支持!現在向初學者解釋這個問題。 :d –