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, 2019 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, 2019 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, 2019 in Python by Nymeria
• 3,540 points
0 votes
1 answer
0 votes
4 answers

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

1886 Use del and specify the index of the element ...READ MORE

answered Dec 11, 2020 in Python by Gitika
• 65,970 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,780 points
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,472 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
0 votes
1 answer

Exclusive values from two Sets in Python

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

answered Mar 27, 2019 in Python by Mugdha
• 600 points