how to read a specific line which starts in "#" from file in python -
how can read specific line starts in "#" file in python , set line key in dictionary (without "#") , set lines after line until next "#" value dictionary please me
here file :
please me :(
from collections import defaultdict key = 'nokey' d = defaultdict(list) open('thefile.txt', 'r') f: line in f: if line.startswith('#'): key = line.replace('#', '') continue d[key].append(line)
your dictionary have list of lines under each key. lines come before first line starting '#'
stored under key 'nokey'
.
Comments
Post a Comment