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: 
SOLVED !!!
I can give the explanation with working program

file content of sam.txt

> 
> sam.txt
> 
> 
> Hello this is star hello the data are Hello so you can move to the
> hello
> 
> 
> 

```
file_content = []
resultant_list = []
repeated_element_list = []
with open(file="sam.txt", mode="r") as file_obj:
  file_content = file_obj.readlines()

print("\n debug the file content ",file_content)

for line in file_content:
  temp = line.strip('\n').split(" ")    # This will strip('\n') and split the line with spaces and stored as list
  for _ in temp:
    resultant_list.append(_)

print("\n debug resultant_list",resultant_list)

#Now this is the main for loop to check the string with the adjacent string
for ii in range(0, len(resultant_list)):
  # is_repeated will check the element count is greater than 1. If so it will proceed with identifying duplicate logic
  is_repeated = resultant_list.count(resultant_list[ii])
  if is_repeated > 1:
    if ii not in repeated_element_list:
      for2count = ii + 1
      #This for loop for shifting the iterator to the adjacent string
      for jj in range(for2count, len(resultant_list)):
        if resultant_list[ii] == resultant_list[jj]:
          repeated_element_list.append(resultant_list[ii])

print("The repeated strings are {}\n and total counts {}".format(repeated_element_list, len(repeated_element_list)))

```

**Output:**

```
debug the file content  ['Hello this is abdul hello\n', 'the data are Hello so you can move to the hello']

 debug resultant_list ['Hello', 'this', 'is', 'abdul', 'hello', 'the', 'data', 'are', 'Hello', 'so', 'you', 'can', 'move', 'to', 'the', 'hello']

The repeated strings are ['Hello', 'hello', 'the']
 and total counts 3

```

Thanks
For this kinda file;

```
A hearth came to us from your hearth
foreign hairs with hearth are same are hairs

```

This will check `whole` poem;

```
lst = []
with open ("coz.txt") as f:
    for line in f:
        for word in line.split(): #splited by gaps (space)
            if word not in lst:
                lst.append(word)
            else:
                print (word)

```

Output:

```
>>> 
hearth
hearth
are
hairs
>>> 

```

As you see there are two `hearth` here, because in whole poem there are 3 `hearth`.

For check line by line;

```
lst = []
lst2 = []
with open ("coz.txt") as f:
    for line in f:
        for word in line.split():
            lst2.append(word)
            for x in lst2:
                if x not in lst:
                    lst.append(x)
                    lst2.remove(x)
print (set(lst2))

>>> 
{'hearth', 'are', 'hairs'}
>>> 

```