Set is not orderly.
In your question you use type set
to define the sequence, in python this type is a data structure that represents a sequence denoting a mathematical set, ie you can not impose or maintain any particular order of elements. The abstract concept of a mathematical set does not assume order, for example, if you create a type set
from a list, python automatically changes the order of the elements to meet the internal% implementation-optimized directives to execute the proposed operations for this type.
See these examples:
set={'z','b','c'}
print(set)
{'c', 'b', 'z'}
set.add('a')
print(set)
{'c', 'b', 'z', 'a'}
set.add('e')
print(set)
{'a', 'b', 'c', 'e', 'z'}
# Obs. Novos testes com os mesmos valores podem gerar resultados diferentes
You could get what you want with set
, see:
lst = [1,2,3,4,5]
lst.remove(5)
print(lst)
[1, 2, 3, 4]
lst.insert(0,5)
print(lst)
[5, 1, 2, 3, 4]
Tip:
To find the position of an element in a list, do: list