This commit is contained in:
Tarmo Sillajõe
2018-12-05 16:21:56 +02:00
parent 7c8eb4fbad
commit 8c11686054

View File

@@ -14,10 +14,6 @@ Read the text file to a list mylist where eache item is a row.
""" """
testlist = ['kass','koer']
print('Koer on ' + str(testlist.index('koer')) + 's.' )
def lines_generator(placeholder=0): def lines_generator(placeholder=0):
with open("tabel.txt", "rt") as f: with open("tabel.txt", "rt") as f:
for line in islice(f,0,6 ): for line in islice(f,0,6 ):
@@ -45,15 +41,16 @@ def myfunc(mylist):
mylist.pop(pop_index) mylist.pop(pop_index)
############################################################################# #############################################################################
mylist = ['ladu2','ladu3'] mylist = ['ladu2','ladu3','ladu1']
p = re.compile("|".join(mylist)) p = re.compile("|".join(mylist))
stock = 'ladu2'
for line in mylines: for line in mylines:
if not p.search(line): if not p.search(line):
line = line.rstrip('\n') line = line.rstrip('\n')
line += '\tladu2' line += '\t' + p.search(line).group(0)
filecontent.append(line) filecontent.append(line)
else: else:
pop_index = mylist.index(p.search(line).group(0)) pop_index = mylist.index(p.search(line).group(0))