There is a list, which includes the following data,
a = ['key1=value1','key2=value2','key3=value3',...,'key100=value100']
I write the code below, which converts the list to one dict in one line,
b = dict((list(item.split('='))[0], list(item.split('='))[1]) for item in a
(My Python version is 2.6, which doesn't support dictionary comprehension.)
My question:
Is there a way to rewrite the code, which is more condense? e.g.,
b=dict(x,y) for item.split('=') in a [WRONG]
I felt list(item.split('='))[0]
and list(item.split('='))[1]
is really cumbersome.
[Update]
@TigerhawkT3, the link Alternative to dict comprehension prior to Python 2.7 doesn't solve my problem, because my question is nothing with learning how to write dict comprehension prior to Python 2.7.