Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

py random.smple

# Python3 program to demonstrate
# the use of sample() function .
  
# import random 
import random
  
  
# Prints list of random items of
# length 3 from the given list.
list1 = [1, 2, 3, 4, 5, 6] 
print("With list:", random.sample(list1, 3))
  
# Prints list of random items of
# length 4 from the given string. 
string = "GeeksforGeeks"
print("With string:", random.sample(string, 4))
  
# Prints list of random items of
# length 4 from the given tuple.
tuple1 = ("ankit", "geeks", "computer", "science",
                   "portal", "scientist", "btech")
print("With tuple:", random.sample(tuple1, 4))
  
  
# Prints list of random items of
# length 3 from the given set.
set1 = {"a", "b", "c", "d", "e"}
print("With set:", random.sample(set1, 3))
Comment

py random.smple

# Python3 program to demonstrate
# the use of sample() function .
  
# import random 
import random
  
  
# Prints list of random items of
# length 3 from the given list.
list1 = [1, 2, 3, 4, 5, 6] 
print("With list:", random.sample(list1, 3))
#  With list: [3, 1, 2]

# Prints list of random items of
# length 4 from the given string. 
string = "GeeksforGeeks"
print("With string:", random.sample(string, 4))
#  With string: ['e', 'f', 'G', 'G']  
  
# Prints list of random items of
# length 4 from the given tuple.
tuple1 = ("ankit", "geeks", "computer", "science",
                   "portal", "scientist", "btech")
print("With tuple:", random.sample(tuple1, 4))
#  With tuple: ['ankit', 'portal', 'geeks', 'computer']
  
# Prints list of random items of
# length 3 from the given set.
set1 = {"a", "b", "c", "d", "e"}
print("With set:", random.sample(set1, 3))
#  With set: ['b', 'd', 'c']
Comment

py random.smple

# Python3 program to demonstrate
# the use of sample() function .
  
# import random 
import random
  
  
# Prints list of random items of
# length 3 from the given list.
list1 = [1, 2, 3, 4, 5, 6] 
print("With list:", random.sample(list1, 3))
  
# Prints list of random items of
# length 4 from the given string. 
string = "GeeksforGeeks"
print("With string:", random.sample(string, 4))
  
# Prints list of random items of
# length 4 from the given tuple.
tuple1 = ("ankit", "geeks", "computer", "science",
                   "portal", "scientist", "btech")
print("With tuple:", random.sample(tuple1, 4))
  
  
# Prints list of random items of
# length 3 from the given set.
set1 = {"a", "b", "c", "d", "e"}
print("With set:", random.sample(set1, 3))
Comment

PREVIOUS NEXT
Code Example
Python :: Python List Comprehension: Elegant way to create Lists 
Python :: Python Old style formatting 
Python :: admin email errors 
Python :: RC style Relative Referencing in OpenPyXL 
Python :: Regular Expressions In Practical NLP example 
Python :: qrcode how to add logo inside python 
Python :: numpy addition operation using numpy functions 
Python :: plotly two y axis bar chart grouped 
Python :: Get hours, minutes, seconds, and microseconds using time class 
Python :: model summary change size of columns 
Python :: NxN Array 
Python :: bee swarm plot 
Python :: dataframe to DatasetDict 
Python :: Python RegEx Escape – re.escape() Syntax 
Python :: python interate with two list 
Python :: how to select the three highest entries within a category in pandas 
Python :: auto clicker 
Python :: what is topic modelling in nlp 
Python :: rpi pip3 installieren 
Python :: python cheat sheets 
Python :: variance in machine learning 
Python :: ERROR: Target path exists but is not a directory, will not continue. 
Python :: 1046 - Game Time 
Python :: Creaing your own functions 
Python :: appears in json dump 
Python :: calculate speed with time in datetime python 
Python :: asp blocking sedular python stackoverflow 
Python :: dataframe groupby rank by multiple column value 
Python :: print less than specific number in one row python 
Python :: linux desktop files location python 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =