text parsing - Removing values from a list in python -
I have a large file of names and values on a single line separated by space:
Name 1 Name 2 Name 3. ....
After a long list of names, there is a list of values corresponding to names. Values can be 0-4 or not, what I want to do is consolidate the data file and delete all names and values when the value is na
for example For, the last line of the name in this file is:
NominateStolat NamesNenNetHelast 0N2
I
< P> I agree with Justin using a zip. It's a good idea to have problems with two different lists How to put the data here is a proposal that should work fine.
reader = open ('input.txt') author = open ('output.txt', 'w') name, nums = [], [] line = reader.read () . Zip (line [, x], line [X:]) for segment ('') x = lane (line) / 2 (n, v) in [n, v] z in z, if we! = 'No']: names.append (a) nums.append (b) writer.write ('' .joye (name)) Author. Written ('') Writer. #. Writer (Written)) # Author. Write ('' .joya (name + points)) is good, but concat.
Comments
Post a Comment