0

How can I take a dictionary having one key-value pair and split the value as follows-

a={"description":"hello,hi,hey,hola"}

Now I would like to split the value through second comma and store the two values as(creating a new key-value pair in the dictionary)--

a={"description":"hello,hi","kkajan":"hey,hola"}

1 Answer 1

1

Something like,

>>> a_split = a['description'].split(',')
>>> a_list = { 'description' : ','.join(a_split[:2]), 'kkajan' : ','.join(a_split[2:]) }
>>> a_list
{'kkajan': 'hey,hola', 'description': 'hello,hi'}
Sign up to request clarification or add additional context in comments.

1 Comment

@kra You are welcome. Please upvote and accept the answer if it helped you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.