Set to a list
Write a Python program to convert a set to a sorted list.
{"python", "java", "go"}['go', 'java', 'python']
Approach
sorted()returns a list in a predictable order.
Solution
langs = {"python", "java", "go"}print(sorted(langs))['go', 'java', 'python']
Line by line
list(langs) also works, but the order of string items can change between runs; sorted fixes it.
Learn the concept
New to this topic? Read the lesson, then come back.