在這種特殊情況下,相應單詞在其各自列表中的位置是相同的。所以你可以只將它們一起zip()
;
In [1]: german = ['Der', 'Hund', 'ist', u'groß', 'und', 'freundlich']
In [2]: english = ['The', 'dog' , 'is', 'big', 'and', 'friendly']
In [3]: zip(german, english)
Out[3]: [('Der', 'The'), ('Hund', 'dog'), ('ist', 'is'), (u'gro\xdf', 'big'), ('und', 'and'), ('freundlich', 'friendly')]
的回答你的問題#1:
In [4]: together = zip(german, english)
In [5]: together[0][0] == 'ist'
Out[5]: False
而對#2:
In [6]: together[-1][0] == u'groß'
Out[6]: False
問題#3,#4違反了該名單是建立的前提,所以他們不能根據名單直接回答。
編輯: 要回答你最後的問題,你需要建立一個德語 - 英語字典。 Python恰好有一個內置的dictionary type。一般
In [3]: ge = {}
In [4]: for g, e in zip(german, english):
...: ge[g] = e
...:
In [5]: ge
Out[5]: {'Der': 'The', 'ist': 'is', 'und': 'and', u'gro\xdf': 'big', 'Hund': 'dog', 'freundlich': 'friendly'}
問題3現在變成:
In [6]: german[0] == 'ist' and german[1] == u'groß' and english[-2] == ge['ist'] and english[-1] == ge[u'groß']
Out[6]: False
問題4:
In [16]: german[-2] == 'ist' and german[-1] == u'groß' and english[0] == ge['ist'] and english[1] == ge[u'groß']
Out[16]: False
引述了評論[從以前的問題(http://stackoverflow.com/questions/14865404/write-rows-in-columns-in-file-in-python#comment20839324_14865404):「這些都是非常好的規範,你有什麼問題?請編輯你的帖子以包含你最新的嘗試,你在正確的方向,謝謝。「 – DSM 2013-03-23 17:29:36