Python - Use unique element from a set

0 votes
I have a scenario where I have a sequence of unique values. I need use these unique values one at a time and the value should be selected randomly. Also, the value should not be available for use again. Which function/functions will be useful?
Mar 26 in Python by Mishti
• 480 points

1 answer to this question.

0 votes

The best way to achieve this by using the pop function. Assuming the unique values are available in a set, say s1={2,5,7,9}, then the function results as shown below-

Hope this helps.

answered Mar 27 by Mugdha
• 600 points

Related Questions In Python

0 votes
1 answer

Extract element from a set without removing it

Use iter(): element = next(iter(set_1)) READ MORE

answered Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21 in Python by Nymeria
• 3,520 points
0 votes
1 answer
0 votes
1 answer

How do I remove an element from a list by index in Python?

You can use the pop() method to ...READ MORE

answered Jun 21 in Python by Nisa
• 1,090 points
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 331 views
+4 votes
6 answers
0 votes
1 answer

Exclusive values from two Sets in Python

There is a direct function available to ...READ MORE

answered Mar 27 in Python by Mugdha
• 600 points