Sorted String in Python

Level 120 keystrokes

This sorts characters in a string. The sorted() function returns a list of characters in order.

Python code

# sorted() takes any iterable; a string is iterated character by character
# It always returns a new list, here ['a', 'b', 'c'] in alphabetical order
1print(sorted("cba"))

Output

['a', 'b', 'c']
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • "× 2
  • (× 2
  • )× 2

More Python examples at level 1

← Python typing practice