I have a csv file and am working on a custom dictionary function where I would like to append values by user input; but, it is appending multiple times.
Which keys are occurring is shown in image:1.
I just want to append only once and then, depending on user input, restart the loop.
Gender name appending multiple times:
def dict2(data):
data1=data
empty = {}
print ("Column names at first row",data1[0])
print ("Total number of columns found: ", len(data1[0]))
x=int(input("Please enter KEY column no.: "))-1
print("Working on:",data1[0][x]," Column")
y = input("Does data contains headers? Enter 1 or 0 :")
if y == "1":
data1 = data[1:]
z = (input("Do you want to sum unique key values? Enter 1 or 0 :"))
if z == "1":
for i in data1:
if i[x] not in empty:
empty[i[x]] = 1
elif i[x] in empty:
empty[i[x]] +=1
if z == "0":
print ("Column names at first row",data1[0])
z0 = int(input("How many values to assign in KEY: "))
for i0 in range (z0):
z1 = int((input("Please assign a value to key, Enter Column number :")))-1
for i in data1:
if i[x] not in empty:
empty[i[x]] = [1]
empty[i[1]].append(i[z1])
elif i[x] in empty:
empty [i[x]][0]+=1
def inner_func():
zx = input("do u: ")
if zx == "1":
z1 = int((input("Please assign a value to key, Enter Column number :")))-1
for i in data1:
if i[x] not in empty:
empty [i[x]][0]+=1
elif i[1] in empty:
empty[i[x]].append(i[z1])
zx = input("do u: ")
if zx == "1":
return inner_func()
inner_func()
return empty```