python - How to split some parts of a line? -
python - How to split some parts of a line? -
so have bunch of lines (productions) either of following:
vbd -> 'rattled' pp -> cc pp|<pp-loc-cc-pp> there 1 part on lhs , arrow either 1 or 2 parts on rhs. how can store them or phone call them? (for illustration iterating through lines (productions) , check if lhs vbd or rhs rattled (for first pattern) or rhs0 cc , rhs1 pp-pp| (for sec pattern) )?
again, pattern in productions follows 1 of following:
a -> 'b' or
c -> d e a, b, c, d , e can (numbers, letters, signs etc.)
if want split each line head (e.g. vbd) , tail (e.g. 'rattled'), 1 easy way utilize split operator so:
for line in lines: split_line = line.split(" -> ") head = split_line[0] tail = split_line[1] this assumes every single line has 1 incidence of " -> ", , each line has space on each side of "->" separator.
i'm not sure understand specifics of implementation, if wanted check whether given tail 'rattled' or cc pp|<pp-loc-cc-pp>, iterate through tail so:
for token in tail: if token[0] == "'": # string, 'b' else: # d e etc. two_part_style_split = token.split(' ') two_part_style_split so:
['cc', 'pp<pp-loc-cc-pp>'] python loops split
Comments
Post a Comment