-
-
Save originalankur/4662918 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def normalize_line(line): | |
return [piece.strip() for piece in line.split("|")[1:-1]] | |
def is_valid_line(line): | |
return "|" in line | |
def load(text): | |
lines = map(normalize_line, | |
filter(is_valid_line, | |
text.strip().splitlines())) | |
keys = lines.pop(0) | |
return [dict(zip(keys, line)) for line in lines] | |
print load(""" | |
------------------------------------------- | |
| username | password | email | | |
------------------------------------------- | |
| edi | 123456 | | | |
| budu | 123456 | [email protected] | | |
| budu | 123456 | [email protected] | | |
| budu | 123456 | [email protected] | | |
| budu | 123456 | [email protected] | | |
------------------------------------------- | |
""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment