So, I have a large text file. It contains a bunch of information in the following format:
|NAME|NUMBER(1)|AST|TYPE(0)|TYPE|NUMBER(2)||NUMBER(3)|NUMBER(4)|DESCRIPTION|
Sorry for the uncertainty. All information is formatted as described above, and there is a separator '|' between each descriptor. I want to be able to search for a file for "NAME" and print each descriptor in its own tag, such as this example:
Name Number(1): AST: TYPE(0): etc....
In case I am still confused, I want to be able to search for a name and then print out the information following each, separated by a “|” character.
Can anyone help?
EDIT The following is an example of a portion of a text file:
| Trevor Jones | 70 | AST | White | Earth | 3 || 500 | 1500 | Old retired man |
This is the code that I still have:
with open('LARGE.TXT') as fd: name='Trevor Jones' input=[x.split('|') for x in fd.readlines()] to_search={x[0]:x for x in input} print('\n'.join(to_search[name]))
source share