On Dec 17, 4:23 am, "thunderf...@gmail.com" <thunderf...@gmail.com> wrote: > not as slick as Emile's (didn't think about using strip() ), but > seemingly functional: > > data = ['key1: data1','key2: data2','key3: data3',' key4: ',' > \tdata4.1',' \tdata4.2',' \tdata4.3','key5: data5'] > result = {} > > for item in data: > if item.endswith(': '): > currkey = item[:-2] > result[currkey] = [] > elif item.startswith(' \t'): > result[currkey].append(item[2:]) > else: > key, val = item.split(': ') > result[key] = val > > print 'data = %s' % data > print 'result = %s' % result > > > > data = ['key1: data1', 'key2: data2', 'key3: data3', ' key4: ', ' > \tdata4.1', ' \tdata4.2', ' \tdata4.3', 'key5: data5'] > result = {'key3': 'data3', 'key2': 'data2', 'key1': 'data1', 'key5': > 'data5', ' key4': ['data4.1', 'data4.2', 'data4.3']} > > > >
Hi i tried with thunderfoot code error: Traceback (most recent call last): File "<stdin>", line 8, in ? ValueError: need more than 1 value to unpack -- http://mail.python.org/mailman/listinfo/python-list