Skip to content

Instantly share code, notes, and snippets.

@Deniz97
Last active February 17, 2021 07:29
Show Gist options
  • Save Deniz97/b3157636aee3e0368a2ddcb2c907b374 to your computer and use it in GitHub Desktop.
Save Deniz97/b3157636aee3e0368a2ddcb2c907b374 to your computer and use it in GitHub Desktop.
with open("sample_prices.txt", "r") as myfile:
all = myfile.readlines()
prices = [ ]
for line in all:
l = line.split(":")
prices.append( (l[0], l[1] ))
counter = 1
memory = [prices[0][0]]
current_price = prices[0][1]
for p in prices[1:]:
if p[1] == current_price:
counter += 1
if counter < 3:
memory.append(p[0])
elif counter == 3:
print()
for m in memory:
print(m)
print(p[0])
elif counter > 3:
print(p[0])
else:
memory = [p[0]]
counter = 1
current_price = p[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment