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
• 440 points
34 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 500 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
8 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 in Python by Nymeria
• 3,500 points
162 views
0 votes
1 answer
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,710 points
40 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
424 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
24 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
• 500 points
29 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.