Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an arbitrary element in Python?

I'm reading about sets and see terms like "specific" elements and "arbitrary" elements. For example: "The method remove removes a specific element from a set; pop removes an arbitrary element". Can someone explain arbitrary elements?

like image 484
jasmine Avatar asked Dec 01 '16 17:12

jasmine


2 Answers

ar·bi·trar·y ˈärbəˌtrerē/ adjective, based on random choice or personal whim, rather than any reason or system.

In the context of your question, "arbitrary element" simply means an element not chosen by you. From the program's perspective, the element was chosen randomly and unpredictably.

Consider:

x = set([1,2]).pop()

x might have the value 1 or 2, but you cannot predict beforehand which one it will be.

like image 179
Robᵩ Avatar answered Oct 23 '22 00:10

Robᵩ


Sets are unordered.

The remove command takes the element that you specify.

The pop takes any element. There's no way of predicting which

like image 45
Dr Xorile Avatar answered Oct 22 '22 22:10

Dr Xorile