Sorting list containing multiple datatypes in Python -


how sort list containing multiple datatypes in python 3.4? example:- lixt=["tak","jil","son",54,84] lixt.sort()

error: typeerror: '<' not supported between instances of 'int' , 'str'

please proper solution

use sorted(your_list, key=str) simple cases when can sort string representation of item

l = ["tak","jil","son",54,84] sorted(l, key=str) 

output: [54, 84, 'tak', 'jil', 'son']


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -