Help on lists ! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Help on lists !

So when i was coding and used sort() function the program blocked and showed :"can't use '< 'between 'str' and 'list'." I don't understand where the < came from

26th Jul 2022, 8:04 PM
Nihel Beghachi
Nihel Beghachi - avatar
5 Answers
+ 2
name is a list, and my_name is a string so list have different types can't be sorted because internally it checks which is greater or less to place in order. Instead append my_name to name list and apply sort on name list.
26th Jul 2022, 8:31 PM
Jayakrishna 🇮🇳
+ 2
You can do also like list =[*name, my_name ] You're welcome...
26th Jul 2022, 8:39 PM
Jayakrishna 🇮🇳
+ 1
Can you show that code?
26th Jul 2022, 8:20 PM
Jayakrishna 🇮🇳
+ 1
Yes of course! Here: my_name = input() agents = int(input()) name = input().split() list =[name, my_name ] list.sort() yourturn = list.index(my_name) spam=agents/yourturn time=(spam*20)+20 print(time)
26th Jul 2022, 8:28 PM
Nihel Beghachi
Nihel Beghachi - avatar
+ 1
It worked! Thank you so much for your time i didn't know this until now
26th Jul 2022, 8:38 PM
Nihel Beghachi
Nihel Beghachi - avatar