下面是我到目前为止的代码。
rawcountries =[]
countries = []
cursor1 = collection.find({})
cursor2 = collection.find({})
for document1 in cursor1:
finding1 = str(document1['rawCountry'])
edited = finding1 + ":"
print(edited)
rawcountries.append(edited)
for document2 in cursor2:
finding2 = document2['country']
countries.append(finding2)
现在在print rawcountries
列表中,我有:
['Jakarta (Lippo):', 'Petaling Jaya (Empire City):', 'Singapore (Cecil `Court):', 'Singapore (Cecil Court):', 'Singapore (Marina One):', 'Singapore (Marina One):', 'Jakarta (Lippo):', 'Singapore (Cecil Court):', 'Singapore (Marina One):', 'Bangalore (Salarpuria Adonis):',....`
在print countries
列表中的下一个,我有:
[u'ID', None, u'SG', u'SG', u'SG', u'SG', u'ID', None, u'SG', None, u'ID', u'SG', u'SG', u'SG', u'SG', u'SG', u'SG', u'MY', u'MY', u'US', u'ID', u'SG', u'ID', None, u'US', None, None, None, u'US', u'MM', u'KH',
我想将两个列表都添加为如下格式:
[ "Jakarta (Lippo):ID" , "Petaling Jaya (Empire City): None ", "Singapore (Cecil `Court): SG ", ........."]
所以,问题是我该怎么办?
答案 0 :(得分:-1)
如果您知道列表的长度相同,则可以使用zip:
result = [r+str(c) for (rc,c) in zip(rawcountries, countries)]