Question: I want to make a program which would compare 2 .csv files, and print the rows that are in one of them, but not in the other. It basically works, but it stops working after performing 2 tasks in this program :/ I'm a Python beginner.

```
csv=open('c:\Users\***\Desktop\prvi.csv','r')
csv2=open('c:\Users\***\Desktop\drugi.csv','r')

list1=[]
choice=0
loop=0
while loop==0:
    choice=input('Odaberite zeljenu funkciju: \n1)\
 Usporedi Book1 sa Book2\n2) Usporedi Book2 sa Book1 \n3) Print Book1 \n4) Print Book2 \n5) Izlaz \nOdabir: ')
    if choice==1:
        for row in csv:
            if not row in csv2:
                list1.append(row)
                for row in list1:
                    print row
                    del list1[0:len(list1)]
    elif choice==2:
        for row in csv2:
            if not row in csv:
                list1.append(row)
                for row in list1:
                    print row
                    del list1[0:len(list1)]
    elif choice==3:
        for row in csv:
            print row
    elif choice==4:
        for row in csv2:
            print row
    elif choice==5:
        loop=1

```

Answer: 
You probably need to rewind or re-open the files, since after iterating over the contents once, the files are "exhausted".
If there are no duplicates in your csv files which have to be retained in the output, I'd use sets here and simply let Python compute the difference.

[From the documentation:](http://docs.python.org/py3k/library/stdtypes.html#set-types-set-frozenset)

> 
> difference(other, ...)  
> 
>  set - other - ...  
> 
>  Return a new set with elements in the set that are not in the others.
> 
> 
> 

```
csv = set(open(r'c:\Users\***\Desktop\prvi.csv', 'r').read().split('\n'))
csv2 = set(open(r'c:\Users\***\Desktop\drugi.csv', 'r').read().split('\n'))

#...

# get everything in csv1, but not in csv2
diff1 = csv1 - csv2
# get everything in csv2, but not in csv1
diff2 = csv2 - csv1

```