How can i modify this code that it will ingored Case sensitive for PYTHON: Pleas
ID: 3862057 • Letter: H
Question
How can i modify this code that it will ingored Case sensitive for PYTHON:
Please enter a word (or just hit enter to end): Ana
Please enter a word (or just hit enter to end): Bill
Please enter a word (or just hit enter to end): button
Please enter a word (or just hit enter to end): car
Please enter a word (or just hit enter to end): avoid
Please enter a word (or just hit enter to end):
The structure contains 5 items:
Ana Bill avoid button car
I want to print: Ana avoid Bill button car
import sys
sys.path.append
from node import Node
def length(head):
probe = head
count = 0
while probe != None:
probe = probe.next
count+=1
return count
def insert(newItem, head):
newNode = Node(newItem)
if head == None:
head = newNode
else:
if newItem < head.data:
newNode.next = head
head = newNode
else:
probe = head;
while probe.next and probe.next.data probe = probe.next
newNode.next = probe.next;
probe.next = newNode
return head
def printStructure(head):
probe = head
answer = ""
while probe:
answer = answer + probe.data + " "
probe = probe.next
print(answer)
def main():
head = None
userInput = input('Please enter a word (or just hit enter to end): ')
while userInput != '':
head = insert(userInput, head)
userInput = input('Please enter a word (or just hit enter to end): ')
print('The structure contains', length(head), 'items:')
printStructure(head)
if __name__ == "__main__": main()
Explanation / Answer
whenever you are inserting the value in list u comparing with the current head value and after comparing you are inserting that value to the ascending order so at that time u need to use lower() function when comparing two string. it will give you case insensitive.
def insert(newItem, head):
newNode = Node(newItem)
if head == None:
head = newNode
else:
if newItem.lower() < head.data.lower():
newNode.next = head
head = newNode
else:
probe = head;
while probe.next and probe.next.data probe = probe.next
newNode.next = probe.next;
probe.next = newNode
return head
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.