Mar-02-2022, 04:42 PM
(Feb-17-2021, 01:09 AM)theyhateadam Wrote: male_names = { 'Oliver', 'Declan', 'Henry' }
This is a
set
literal. A set has only unique elements, and it does not keep any order.For example, I get this order back: {'Declan', 'Henry', 'Oliver'}
If you want to get an alphanumerical order, you can use
sorted
on the set
.sorted_unique_names = sorted(male_name)If the insertion order is important for you, then don't use a
set
. Instead, use a list
.You can't use a
tuple
because a tuple
is immutable, and you can not add or remove elements from a tuple
.Since Python 3.6
dict
s also keep the insertion order of keys and since Python 3.7 it's a standard of the Python language. Sometimes this feature is used, to get a set-like object with keeping the order.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!