Форум сайта python.su
Имею данные
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()))
Отредактировано kripton3000 (Фев. 7, 2014 15:56:53)
Офлайн
data.splitlines() ['', 'rules: evdev', 'model: pc105', 'layout: us,ru', 'variant: ,', 'options: grp:alt_shift_toggle,grp_led:scroll']
Офлайн
>>> data = """ ... rules: evdev ... model: pc105 ... layout: us,ru ... variant: , ... options: grp:alt_shift_toggle,grp_led:scroll ... """ >>> >>> d = {k.strip():v.strip() for k, v in ... (i.split(':', 1) for i in data.splitlines() if i.strip())} >>> >>> print(d) {'options': 'grp:alt_shift_toggle,grp_led:scroll', 'rules': 'evdev', 'model': 'pc105', 'variant': ',', 'layout': 'us,ru'} >>>
Отредактировано py.user.next (Фев. 7, 2014 18:18:54)
Офлайн