I have a dictionary that looks like :
dict={'name':'ed|tom|pete','surname':'abc|def'}
How do I convert the keys with the delimeter | into a list ? Something that looks like:
dict1={'name':['ed','tom','pete'],'surname':['abc','def']}
thanks...
I have a dictionary that looks like :
dict={'name':'ed|tom|pete','surname':'abc|def'}
How do I convert the keys with the delimeter | into a list ? Something that looks like:
dict1={'name':['ed','tom','pete'],'surname':['abc','def']}
thanks...
 
    
    You can iterate through each keys and split it on the delimeter
for key in dict1.keys():
    dict1[key] = dict1[key].split('|')
Sample Input:
>>dict1={'name':'ed|tom|pete','surname':'abc|def'}
Sample Output:
>>dict1
{'name': ['ed', 'tom', 'pete'], 'surname': ['abc', 'def']}
 
    
    Use a dict-comprehension along with str.split
values = {'name': 'ed|tom|pete', 'surname': 'abc|def'}
values = {k: v.split("|") for k, v in values.items()}
