parse unformatted string into dictionary with python
- by user553131
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.