Answers for "python string as dictionary key"

4

poython str to dict

>>> D1={'1':1, '2':2, '3':3}
>>> s=str(D1)
>>> import ast
>>> D2=ast.literal_eval(s)
>>> D2
{'1': 1, '2': 2, '3': 3}
Posted by: Guest on June-30-2020
0

python dict keys to string

myList = ['Tom', 'Lisa', 'Chris', 'Joe']
separator = ' and ' # note the spaces around

s = separator.join(myList)

print(s)

## outputs:
## Tom and Lisa and Chris and Joe
Posted by: Guest on August-16-2020

Code answers related to "python string as dictionary key"

Python Answers by Framework

Browse Popular Code Answers by Language