0

this is how my text file looks like

8888888888

6777777667

212123344121212

14141414141414141414

111121222224

68888888812

66666663314

what is the approach i can do ?please help

I am trying this code`

list1=content.New_Pair def unique(list1):

# intilize a null list 
unique_list = [] 

# traverse for all elements 
for x in content.New_Pair: 
    # check if exists in unique_list or not 
    if x not in unique_list: 
        unique_list.append(x) 
# print list 
for x in unique_list: 
    print(x)

`

  • Does this answer your question? [How to make lists contain only distinct element in Python?](https://stackoverflow.com/questions/4459703/how-to-make-lists-contain-only-distinct-element-in-python) – Emiliano Ruiz Jan 31 '20 at 17:05
  • can you provide the desired output, it's not clear what you are trying to get. – marcos Jan 31 '20 at 17:08
  • desired is to get unique values from text file its has more then 40k values like 8888888888 6777777667 what i want it to compare each row of values with each other and find the unique between them not to get the unique values from all the values –  Jan 31 '20 at 17:11

1 Answers1

0

Method 1 : Traversal of list

Using traversal, we can traverse for every element in the list and check if the element is in the unique_list already if it is not over there, then we can append it in the unique_list. This is done using one for loop and other if statement which check if the value is in the unique list or not which is equivalent to another for loop

Method 2 : Using Set

Using set() property of Python, we can easily check for the unique values. Insert the values of the list in a set. Set only stores a value once even if it is inserted more then once. After inserting all the values in the set by list_set=set(list1), convert this set to a list to print it.

Devesh mehta
  • 1,505
  • 8
  • 22
  • list1=content.Pair print(list1) #function to get unique values def unique(list1): unique_list = [] print(unique_list) for x in list1: if x not in unique_list: unique_list.append(x) for x in unique_list: print(x) –  Feb 03 '20 at 11:04