我有兩個列表:Zip函數沒有在Python中返回預期的結果?
a = ['a', 'b', 'c']
b = [1]
我希望我的輸出:
a, 1
b, 1
c, 1
試着這樣做:
for i, j in zip(a, b):
print i, j
我只得到a, 1
。我怎樣才能做到這一點?
這是我的實際情況:
if request.POST.get('share'):
choices = request.POST.getlist('choice')
person = request.POST.getlist('select')
person = ''.join(person)
person1 = User.objects.filter(username=person)
for i, j in izip_longest(choices, person1, fillvalue=person1[-1]):
start_date = datetime.datetime.utcnow().replace(tzinfo=utc)
a = Share(users_id=log_id, files_id=i, shared_user_id=j.id, shared_date=start_date)
a.save()
return HttpResponseRedirect('/uploaded_files/')
我不知道什麼類型的對象呢'User.objects .filter(username = person)'返回,可能是它返回一個迭代器? –
沒關係!用0替換解決了問題 – user1881957