List in python, heeeeelp meeeee sensie | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

List in python, heeeeelp meeeee sensie

myList = ["Nani", "onichan", "kodasai"] How do i get rid of these errors? What i am going to do here is to find the exact index number of my list even i put lower cases string. Example, Sample = myList.index("nani" ) This turns into error result since nani is not in the list unless, the "n" will be capitalized. I already use .lower() function while converting the list of myList into lower cases but i put it in another variable and it works, but is there another way to make this simple and not complicated?

28th Feb 2021, 9:53 AM
Kakai
Kakai - avatar
13 Answers
+ 2
You should lowercase the way i updated in the code. mylist[i]=mylist[i].lower() Explanation: Because only this will lowercase the character and will updated the value lowercased in the list concurrently
28th Feb 2021, 6:05 PM
Nihar Buliya
Nihar Buliya - avatar
+ 3
May be....it should work. Sample = myList.index("nani".lower())
28th Feb 2021, 9:58 AM
Naveen Rathore
Naveen Rathore - avatar
+ 2
Abhay here *input a teammate names "but capitalized" *input checker in "lower cases" Sample: Name: KENT, BEN, YEN checker: kent Output// nope list = [] print("Enter teammates") for i in range(3): list += [input("Enter name: ")] while True: check = input("\nCheck name: ") if check in list: print("Present") else: print("Nope")
28th Feb 2021, 10:26 AM
Kakai
Kakai - avatar
+ 2
Nihar Buliya yup, its mine.
28th Feb 2021, 5:50 PM
Kakai
Kakai - avatar
+ 2
Ok if that's the exact code. It is showing error if i am checking for "nani" in the list. The error message is "nani is not in the list" so the question here is what are you using to lowercase the list elements?
28th Feb 2021, 5:54 PM
Nihar Buliya
Nihar Buliya - avatar
+ 2
Nihar Buliya so, how do i get rid of that thing?
28th Feb 2021, 5:55 PM
Kakai
Kakai - avatar
+ 2
Also you can try use a method to change the string itself my_list = ['Nani', 'Onichan', 'Kodasai'] Sample = my_list.index('nani'.capitalize()) capitalize () it's the method to make only the first letter to Capital Capital letter
2nd Mar 2021, 12:34 AM
Emil Colina
Emil Colina - avatar
+ 1
Naveen Rathore nope, u r just trying to lower the cases of your sample variable. also in that case, your sample variable is nothing to do with the list. U r doing this >> ...("NANI".lower()) >> output: nani >> sample.
28th Feb 2021, 10:01 AM
Kakai
Kakai - avatar
+ 1
I didn't understand what exactly you are looking for but code by Naveen Rathore works fine
28th Feb 2021, 10:10 AM
Abhay
Abhay - avatar
+ 1
Above is another example, it always turns to nope if i put lower cases in checker name
28th Feb 2021, 10:30 AM
Kakai
Kakai - avatar
+ 1
Kakai so can't you make names lowercase when user adds an input , like list += [input("Enter name: ").lower()] Or list should only have the same case of letters as input ?
28th Feb 2021, 10:48 AM
Abhay
Abhay - avatar
+ 1
It is showing the same error for me even if i am putting the mylisy.index() into variable..Can you check if that was your code? https://code.sololearn.com/c7A083A6A9a1/?ref=app
28th Feb 2021, 5:48 PM
Nihar Buliya
Nihar Buliya - avatar
0
Run a loop for list and convert all characters to lowercase and then you can get the index .
1st Mar 2021, 2:57 PM
suman bhardwaj
suman bhardwaj - avatar