Answer the question
In order to leave comments, you need to log in
How to create a Python dictionary?
I have data:
data = """
rules: evdev
model: pc105
layout: us,ru
variant: ,
options: grp:alt_shift_toggle,grp_led:scroll
"""
dict((a, b.strip()) for a, b in
(item.split(":") for item in
data.splitlines()))
Answer the question
In order to leave comments, you need to log in
Maybe it's a bunch of colons "options: grp: alt_shift_toggle, grp_led: scroll"
Although here:
d = {}
for x in data.splitlines():
x = x.split(': ')
if x[0]: d[x[0]] = x[1]
print d
As for the error, you forgot one closing parenthesis:
dict((a, b.strip()) <-- add a parenthesis here
, which doesn't help, because the syntax is wrong :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question