1
Good afternoon, I’m having trouble adding elements of a list to a dictionary.
The list elements to put in the dictionary are:
['Joao', '83889023', 'Maria', '81944356', 'Marcos', '32258899', 'Ana', '88235423', 'George', '1254345', 'Rafaela', '8899345671', 'Pedro', '83223345', 'Aline', '842234565', 'Carlos', '83554463', 'Julia', '13565446', 'Murilo', '23543646', 'Mayra', '233253425', 'Italo', '842142543', 'Rita', '3253464457', 'Aldo', '77443456', 'Raquel', '8384423553', 'Henrique', '88342235', 'Joyce', '987676342', 'Daniel', '3253456346', 'Livia', '325346634', 'Pablo', '87461723', 'Carla', '87351236']
The problem is: In the key will have to be the number and the value will have to be the name.
What I tried was:
dic = {}
x = 0
y = 0
for elem in dados:
dic[elem] = dados[y]
x = x + 1
y = y + 1
print(dic)
But what I get is:
{'Joao': 'Joao', '83889023': '83889023', 'Maria': 'Maria', '81944356': '81944356', 'Marcos': 'Marcos', '32258899': '32258899', 'Ana': 'Ana', '88235423': '88235423', 'George': 'George', '1254345': '1254345', 'Rafaela': 'Rafaela', '8899345671': '8899345671', 'Pedro': 'Pedro', '83223345': '83223345', 'Aline': 'Aline', '842234565': '842234565', 'Carlos': 'Carlos', '83554463': '83554463', 'Julia': 'Julia', '13565446': '13565446', 'Murilo': 'Murilo', '23543646': '23543646', 'Mayra': 'Mayra', '233253425': '233253425', 'Italo': 'Italo', '842142543': '842142543', 'Rita': 'Rita', '3253464457': '3253464457', 'Aldo': 'Aldo', '77443456': '77443456', 'Raquel': 'Raquel', '8384423553': '8384423553', 'Henrique': 'Henrique', '88342235': '88342235', 'Joyce': 'Joyce', '987676342': '987676342', 'Daniel': 'Daniel', '3253456346': '3253456346', 'Livia': 'Livia', '325346634': '325346634', 'Pablo': 'Pablo', '87461723': '87461723', 'Carla': 'Carla', '87351236': '87351236'}
How do I solve this problem?