Mercurial > hg > config
comparison python/dictify.py @ 880:cd1ebc68739f
-> python3
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Tue, 06 Aug 2019 14:01:21 -0700 |
| parents | 55a9ba575605 |
| children | 4ebb6aff9d67 |
comparison
equal
deleted
inserted
replaced
| 879:79b52aec477e | 880:cd1ebc68739f |
|---|---|
| 2 | 2 |
| 3 divider = ':' | 3 divider = ':' |
| 4 | 4 |
| 5 def dictify(string): | 5 def dictify(string): |
| 6 lines = [ i.strip() for i in string.split('\n') if i.strip() ] | 6 lines = [ i.strip() for i in string.split('\n') if i.strip() ] |
| 7 return dict([i.split(divider,1) for i in lines | 7 return dict([i.split(divider,1) for i in lines |
| 8 if len(i.split(divider,1)) == 2]) | 8 if len(i.split(divider,1)) == 2]) |
| 9 | 9 |
| 10 if __name__ == '__main__': | 10 if __name__ == '__main__': |
| 11 import sys | 11 import sys |
| 12 feh = sys.stdin.read() | 12 feh = sys.stdin.read() |
| 13 thedict = dictify(feh) | 13 thedict = dictify(feh) |
| 14 if sys.argv[1:]: | 14 if sys.argv[1:]: |
| 15 for i in sys.argv[1:]: | 15 for i in sys.argv[1:]: |
| 16 if thedict.has_key(i): | 16 if thedict.has_key(i): |
| 17 print thedict[i] | 17 print (thedict[i]) |
| 18 else: | 18 else: |
| 19 print thedict | 19 print (thedict) |
