Run
import json # Given string x = 'name=apple,quantity=100,price=50' # Item separator item_sep = ',' # Key and value separator key_value_sep = '=' # Convert string to dictionary dictionary = dict(item.split(key_value_sep) for item in x.split(item_sep)) print(f"Dictionary\n{dictionary}")
Output