Help with case insensitive sort - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help with case insensitive sort

dragonflame17dragonflame17 Posts: 1Member
I have writen this code and everything runs, but I wanted to add case insensitivity to avoid the chance of the capitalized words being printed first. Does any one have any ideas on how to make that work, I have tried many different ways, but Im unsure how to work it with a list.

[code]
def main():
names = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0]
index = 0
while index < len(names):
names[index] = raw_input('Enter name number ' + str(index +1)+ ':')
index = index + 1
insertionSort(names)

def insertionSort(names):
index = 0
while index < len(names):
unsortedValue = names[index]
scan = index
while scan > 0 and names[scan - 1] > unsortedValue:
names[scan] = names[scan - 1]
scan = scan - 1
names[scan] = unsortedValue
index = index + 1
print names
main()
[/code]

Comments

  • sundaresanvsundaresanv Posts: 1Member
    Just change the following to the line from:
    names[index] = raw_input('Enter name number ' + str(index +1)+ ':')

    to:
    names[index] = raw_input('Enter name number ' + str(index +1)+ ':').lower()

    --
    Sundaresanv
Sign In or Register to comment.