list - Sort python based on value -
i wrote code fun of it
symbols = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] numbers = [] counter = 0 print("enter name") name = input(">") if name: new_name = list(name) x in range(0, len(symbols)): count_name = new_name.count(symbols[x]) numbers.append(count_name) if count_name: counter += 1 print("character amount =", counter) x in range(0, len(numbers)): if numbers[x]: print(symbols[x], "=", numbers[x]) else: print("input = null")
when come in name illustration roemer
it prints out this:
character amount = 4 e = 2 m = 1 o = 1 r = 2
but want sort based on character occurs frequently
for number, symbol in sorted(zip(numbers, symbols), reverse=true): if number: print(symbol, number)
python list sorting python-3.x
No comments:
Post a Comment