i want to iterate through a list so i can find the index number where the first item in the list finds its first match. my results should print mylist[0:first_match]
here is what i mean:
.APT 5B APT 5B .
.BUSINESS JOEY BUSINESS.
. 1ST FL .
. NATE JR SAM .
. JOE 7 .
. .
.2ND FLR TOM 2ND FLR .
.A1 2FL APT 71E .
.APT E205 APT 1R .
. CONSTRUCTION .
.APT 640 APT 545.
.PART1 SYNC PART2 .
. NATE JR SAM .
the problem im running into is the program keeps adding items to dictionary even after the first match is found therefore appending data that i want to ignore/bypass..
here is what i have:
dictt = {}
with open(path + 'sample33.txt', 'rb') as txtin:
for line in txtin:
part2 = line[1:29].split()
uniq = []
print '%r' % part2
for key in part2:
if key not in dictt:
dictt[key] = key
uniq.append(key)
dictt = {}
print ' '.join(uniq)
Results:
['APT', '5B', 'APT', '5B']
APT 5B
['BUSINESS', 'JOEY', 'BUSINESS']
BUSINESS JOEY
['1ST', 'FL']
1ST FL
['NATE', 'JR', 'SAM']
NATE JR SAM
['JOE', '7']
JOE 7
[]
['2ND', 'FLR', 'TOM', '2ND', 'FLR']
2ND FLR TOM
['A1', '2FL', 'APT', '71E']
A1 2FL APT 71E
['APT', 'E205', 'APT', '1R']
APT E205 1R # Would like to stop adding items after first 'APT' match
['CONSTRUCTION']
CONSTRUCTION
['APT', '640', 'APT', '545']
APT 640 545 # same here...
['PART1', 'SYNC', 'PART2']
PART1 SYNC PART2
['NATE', 'JR', 'SAM']
NATE JR SAM
[Finished in 0.1s]
i hope i have explained this correctly and someone can fine tune it
thank you
Edit #1 here is an example of what i would like to print:
listt:
['APT', '640', 'APT', '1', '2', '3']
found 'APT' match so:
print:
APT 640
ignore ...'APT', '1', '2', '3']