0

trying to compare list of names from a text file, with a list of names from a csv file.

ive created a set of names from the text file using the following:

# receive text and create new list
with open('text.txt') as f:
    lines = f.readlines()
    names = []
    # add first 5 characters from lines to list to get name
    for x in lines[9:1011]:
        names.append(x[0:5])
        names.sort()
        # create set from list to eliminate duplicates
unique_name = set(names)
print(unique_name)

now id like to compare the set with a csv table with a name column and was wondering what the best way to do this is? thank you

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
Yair
  • 99
  • 8
  • See here: https://stackoverflow.com/questions/17186893/accessing-column-data-from-a-csv-file-in-python#17188290 Accessing column data from a CSV file in Python – Claudio Sep 18 '22 at 12:32
  • maybe first don't search `the best way` but `working way` – furas Sep 18 '22 at 18:58
  • first you have to load csv file and create list with rows. And later you can use `for`-loop to check every row in list and compare every name with `set(names)`. OR use `pandas` to make it simpler. – furas Sep 18 '22 at 19:01

0 Answers0