Answer the question
In order to leave comments, you need to log in
How to sort a list of tuples in python in python?
after the work of dict.items() there is a list of tuples of the form
[("a", 2), ("b", 4), ("c", 5), ....]
sorted(array, key=lambda x: -x[1], x[0])
import string
latin_str2 = string.ascii_lowercase
latin_str_list = list(latin_str2)
print(latin_str_list)
print()
numbers = ("1","2","3","4","5","6","7" ,"8","9","0")def check(text):
stroca = text.lower()
Lstr = list(stroca)
print(Lstr)
my_dict = {}
for value in Lstr:
if value in latin_str_list:
counts_0 = text.count(value)
my_dict[value] = counts_0
array = my_dict.items()
print(array)
answer = sorted( array, key = lambda x: x[-1]) # error
print('this is QA :',answer)
return(answer)
All the best!
Answer the question
In order to leave comments, you need to log in
Need to get the substring that occurs most often in a string?
a = [("a", 2), ("c", 5), ("b", 6)]
max(a, key=lambda x: x[1])[0]
=> b
sorted(a, key=lambda x:x[1], reverse = True)
=> [('b', 6), ('c', 5), ('a', 2)]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question