Skip to content

Instantly share code, notes, and snippets.

@Echocage
Created August 24, 2014 21:36
Show Gist options
  • Save Echocage/5ac343fca95b07aa4a25 to your computer and use it in GitHub Desktop.
Save Echocage/5ac343fca95b07aa4a25 to your computer and use it in GitHub Desktop.
data = r"""File Name : File1.txt
Directory : Path\to\File1.txt
Created : 2012:04:15 10:15:32
Accessed : 2012:04:18 13:28:18"""
items = []
for line in data.split('\n'):
type = line.split(':')[0].strip()
rest = ':'.join(map(lambda x: x.strip(), line.split(':')[1:]))
if type == 'File Name':
items.append({type: rest})
else:
items[-1][type] = rest
print ','.join(items[0].iterkeys())
for dictionary in items:
print ','.join(dictionary.itervalues())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment