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
109 views

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
57 views
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,520 points
2,617 views
0 votes
1 answer
0 votes
2 answers

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

Delete the List and its element: We have ...READ MORE

answered Jun 7 in Python by sahil
• 540 points
31,015 views
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
315 views
+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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,371 views
0 votes
0 answers
+4 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,800 points
1,014 views
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
117 views