Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

select randomly from list in loop

>>> num = [1, 2, 3, 4, 5, 6]
>>> while len(num) > 0:
...   n = random.choice(num)
...   print("selected : ", n)
...   num.remove(n)
...   print("num is now: ", num)
... 
selected :  3
num is now:  [1, 2, 4, 5, 6]
selected :  5
num is now:  [1, 2, 4, 6]
selected :  4
num is now:  [1, 2, 6]
selected :  1
num is now:  [2, 6]
selected :  6
num is now:  [2]
selected :  2
num is now:  []
Comment

PREVIOUS NEXT
Code Example
Python :: variable types in python 
Python :: for count in range(size): 
Python :: circular reference detected python repl.it 
Python :: calendar range 
Python :: list of thing same condition 
Python :: Create an identical list from the first list using list comprehension. 
Python :: should i learn c++ or python 
Python :: accessing location of a csv cell in python 
Python :: hmac decrypt python 
Python :: round to nearest multiple of 5 python from both end 
Python :: python project pick text color according to background 
Python :: discertize dara python 
Python :: spark write progress bar jupyter 
Python :: withdraw() opposite tjinter 
Python :: arma-garch python 
Python :: medium how to interact with jupyter 
Python :: which is best between c and python for making application 
Python :: jupyter_ascending 
Python :: get all view port type dynamo revit 
Python :: python fibonacci numbers 
Python :: install matplotlib on nvidia jetson nx 
Python :: self._flush_bg_loading_exception() 
Python :: csv.DictReader Skip Lines 
Python :: how fast is iglob 
Python :: numpy transpose shorthand 
Python :: factorial python 
Python :: get_multiple_items_from_list 
Python :: schema json in oython 
Python :: scipy z value to pvalue 
Python :: overlay bar plot and line plot in python 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =