My task: I have 2 lists different size(1,2,3,4 and "qwe","asd","zxc" for example). How I can create dictionary with this lists with next condition: if count of keys more than values- dict[key]=None. If count of values more-just inore it. My code:
list1=[1,2,3,4]
list2=["qwe","asd","zxc"]
dictx={}
for x in range(len(list1)):
if x>len(list2):
dictx[list1[x]]=None
else:
dictx[list1[x]]=list2[x]
But I catch error: Traceback (most recent call last): File "", line 5, in dictx[list1[x]]=list2[x] IndexError: list index out of range Where I do mistake?Python 3.4 Upd.It's work, but I try to understand where my mistake in this code. Anybody have thought?