Capitalise and Sort in Python

68 Views Asked by At

I have created a small function that sorts the rows in a CSV File alphabetically. However, it sorts them capitalised vs not capitalised. Is there anyway to capitalise all of the entries and then sort them ?

import csv

def CSV_alphabetisch():
    try: 
        reader = csv.reader(open("G.csv"), delimiter=";")
        sortedlist = sorted(reader,)
        with open ("G.csv","w") as new:
          writer = csv.writer(new,delimiter=";")
          for n in sortedlist:
            writer.writerows([n])
    except IndexError:
        print ("Index Error")
CSV_alphabetisch()

I have tried using the .capitalise() function, but I unfortunately get an error message. I would appreciate any help.

Thank you

1

There are 1 best solutions below

1
On

Do you mean: 'string'.capitalize()? (with a 'z')