4

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?

4 Answers 4

4

Something like this?

>>> s='iamonlywhoknock BREAKINGBAD\n'
>>> k, v = s.split()
>>> {k: v}
{'iamonlywhoknock': 'BREAKINGBAD'}
Sign up to request clarification or add additional context in comments.

Comments

3
x='iamonlywhoknock BREAKINGBAD\n'.split(" ")
mydict={x[0]:x[1]}

This should work for you. It is basic string splitting :)

Comments

1

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"))

Comments

0
a = 'iamonlywhoknock BREAKINGBAD\n'
b = a.split()
c = {b[0]:b[1]}

print c

Comments

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.