I am confused by following result in python. The order of the array is changed. How is this valid? I used Spyder IDE to run the code.
arr = {'1','2','3'}
print(arr)
arr.pop()
print(arr)
arr.remove('1')
print(arr)
>>
{'2', '3', '1'}
{'3', '1'}
{'3'}
CodePudding user response:
There is no such thing as array in python.
What you declare in the line arr = {'1','2','3'} is a set, a data structure that doesn't (necessarily) keep the order of the elements.
Please read more about set and python data structures in general: https://docs.python.org/3/tutorial/datastructures.html#sets
