Could you please suggest is there any way to keep all the repeatable (duplicate) keys by adding prefix or suffix. In the below example, the address key is duplicated 3 times. It may vary (1 to 3 times). I want to get the output as in the expected output with adding a suffix to make the key unique. Currently the update function is overwriting the key value.
list = ['name:John','age:25','Address:Chicago','Address:Phoenix','Address:Washington','email:John@email.com']
dic = {}
for i in list:
j=i.split(':')
dic.update({j[0]:j[1]})
print(dic)
Current output: {'name': 'John', 'age': '25', 'Address': 'Washington', 'email': 'John@email.com'}
Expected output: {'name': 'John', 'age': '25', 'Address1': 'Chicago', 'Address2': 'Phoenix', 'Address3': 'Washington', 'email': 'John@email.com'}
Tried the below:
list = ['name:John','age:25','Address:Chicago','Address:Phoenix','Address:Washington','email:John@email.com']
dic = {}
for i in list:
j=i.split(':')
dic.update({j[0]:j[1]})
print(dic)
Expected output: {'name': 'John', 'age': '25', 'Address1': 'Chicago', 'Address2': 'Phoenix', 'Address3': 'Washington', 'email': 'John@email.com'}