元組的一部分,我有這樣的名單:只打印清單
Title , Rating
[('"$weepstake$" (1979) {(#1.2)}', '10.0'),
('"\'Til Death Do Us Part" (2006) {Pilot (#1.0)}', '3.7'),
('"\'Conversations with My Wife\'" (2010)', '4.2')]
如何打印的收視率是這樣的:
10
3.7
4.2
元組的一部分,我有這樣的名單:只打印清單
Title , Rating
[('"$weepstake$" (1979) {(#1.2)}', '10.0'),
('"\'Til Death Do Us Part" (2006) {Pilot (#1.0)}', '3.7'),
('"\'Conversations with My Wife\'" (2010)', '4.2')]
如何打印的收視率是這樣的:
10
3.7
4.2
對於在列表中的每個項目,你需要的第二個項目,其是索引1
:
for item in your_list:
print(item[1])
這會給你想要的輸出。
你的意思是'item [1]'對嗎? –
@JonClements謝謝我做過了,如果你知道我在第一個字符串上的含義,我會困惑一下。 –
什麼:
movies = [('"$weepstake$" (1979) {(#1.2)}', '10.0'), ('"\'Til Death Do Us Part" (2006) {Pilot (#1.0)}', '3.7'),
('"\'Conversations with My Wife\'" (2010)', '4.2')]
print '\n'.join([movie[1] for movie in movies])
試一下,任何東西。如果你可以打印列表中的每個項目,那麼它很容易解釋如何創建一個函數(它本身可以只是一個內聯表達式),從而達到期望的結果。 – user2864740