parse unformatted string into dictionary with python
Posted
by
user553131
on Stack Overflow
See other posts from Stack Overflow
or by user553131
Published on 2010-12-24T10:09:57Z
Indexed on
2010/12/24
20:54 UTC
Read the original article
Hit count: 132
I have following string.
DATE: 12242010Key Type: Nod32 Anti-Vir (30d trial) Key: a5B2s-sH12B-hgtY3-io87N-srg98-KLMNO
I need to create dictionary so it would be like
{
"DATE": "12242010",
"Key Type": "Nod32 Anti-Vir (30d trial)",
"Key": "a5B2s-sH12B-hgtY3-io87N-srg98-KLMNO"
}
The problem is that string is unformatted
DATE: 12242010Key Type: Nod32 Anti-Vir (30d trial)
- there is no space after Date before Key Type
- also it would be nice to have some validation for Key, eg if there are 5 chars in each box of key and number of boxes
I am a beginner in python and moreover in regular expressions. Thanks a lot.
© Stack Overflow or respective owner