For example I have line like this:
iamonlywhoknock BREAKINGBAD
what means
'iamonlywhoknock BREAKINGBAD\n'
Its str, but I need to create Dict, like this:
{"iamonlywhoknock":"BREAKINGBAD"}
Any ideas?
For example I have line like this:
iamonlywhoknock BREAKINGBAD
what means
'iamonlywhoknock BREAKINGBAD\n'
Its str, but I need to create Dict, like this:
{"iamonlywhoknock":"BREAKINGBAD"}
Any ideas?
Something like this?
>>> s='iamonlywhoknock BREAKINGBAD\n'
>>> k, v = s.split()
>>> {k: v}
{'iamonlywhoknock': 'BREAKINGBAD'}
x='iamonlywhoknock BREAKINGBAD\n'.split(" ")
mydict={x[0]:x[1]}
This should work for you. It is basic string splitting :)
The answer in this post is similar to your question:
Splitting a semicolon-separated string to a dictionary, in Python
But you would probably want it to look like this:
s= 'iamonlywhoknock BREAKINGBAD\notherwhoknock BREAKINGBAD2'
dict(item.split(" ") for item in s.split("\n"))