Question: ```
file_str = input("Enter poem: ")
my_file = open(file_str, "r")
words = file_str.split(',' or ';')

```

I have a file on my computer that contains a really long poem, and I want to see if there are any words that are duplicated per line (hence it being split by punctuation).

I have that much, and I don't want to use a module or Counter, I would prefer to use loops. Any ideas?

Answer: 
You can use sets to track seen items and duplicates:

```
>>> words = 'the fox jumped over the lazy dog and over the bear'.split()
>>> seen = set()
>>> dups = set()
>>> for word in words:
        if word in seen:
            if word not in dups:
                print(word)
                dups.add(word)
        else:
            seen.add(word)

the
over

```
```
with open (r"specify the path of the file") as f:
    data =  f.read()
    if(set([i for i in data if f.count(f)>1])):
        print "Duplicates found"
    else:
        print "None"

```