1
1
1 22021-11-14 18:11:59
Python
1 2, 2021-11-14 18:11:59

How to create a dictionary from a certain string?

total = "messages=456?time=05:12:56"

How to get such a dictionary from the total string :

{
  "messages": "456",
  "time": "05:12:56"
}


In addition, so that it is independent of the line:
"messages=456?time=05:12:56?author=you" -> {"messages": "456", "time": "05:12:56", "author": "you"}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-11-14
@0xD34F

dict(n.split('=') for n in string.split('?'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question