Answers for "reverse=true in python"

1

reverse=true in python

#reverse=false is default and reverse=true sort in descending order
# set
py_set = {'e', 'a', 'u', 'o', 'i'}
print(sorted(py_set, reverse=True))

# dictionary
py_dict = {'e': 1, 'a': 2, 'u': 3, 'o': 4, 'i': 5}
print(sorted(py_dict, reverse=True))

# frozen set
frozen_set = frozenset(('e', 'a', 'u', 'o', 'i'))
print(sorted(frozen_set, reverse=True))
#output of all
['u','o','i','e','a']
Posted by: Guest on July-22-2021
47

python sort list

# sort() will change the original list into a sorted list
vowels = ['e', 'a', 'u', 'o', 'i']
vowels.sort()
# Output:
# ['a', 'e', 'i', 'o', 'u']

# sorted() will sort the list and return it while keeping the original
sortedVowels = sorted(vowels)
# Output:
# ['a', 'e', 'i', 'o', 'u']
Posted by: Guest on February-18-2020
5

sorted list python

sorted(iterable, key=None, reverse=False)

type(sorted(iterable, key=None, reverse=False)) = list
Posted by: Guest on May-05-2020

Python Answers by Framework

Browse Popular Code Answers by Language