SHARE
TWEET

Untitled

a guest Jun 19th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. all_data = [1, 2, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 15]
  2.      
  3. >>> random.sample(range(1, 16), 3)
  4. [11, 10, 2]
  5.      
  6. population = [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]
  7. population = set(population)
  8. samples = random.sample(population, 3)
  9.      
  10. all_data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
  11. from random import shuffle
  12. shuffle(all_data)
  13. res = all_data[:3]# or any other number of items
  14.      
  15. from random import sample
  16. number_of_items = 4
  17. sample(all_data, number_of_items)
  18.      
  19. all_data = list(set(all_data))
  20. shuffle(all_data)
  21. res = all_data[:3]# or any other number of items
  22.      
  23. import random
  24. L = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
  25. random.sample(set(L), x) # where x is the number of samples that you want
  26.      
  27. all_data = [1,2,2,3,4,5,6,7,8,8,9,10,11,11,12,13,14,15,15]
  28. choices = []
  29. while len(choices) < 3:
  30.     selection = random.choice(all_data)
  31.     if selection not in choices:
  32.         choices.append(selection)
  33. print choices
  34.      
  35. all_data = [1,2,2,3,4,5,6,7,8,8,9,10,11,11,12,13,14,15,15]
  36.  
  37. # Remove duplicates
  38. unique_data = set(all_data)
  39.  
  40. # Generate a list of combinations of three elements
  41. list_of_three = list(itertools.combinations(unique_data, 3))
  42.  
  43. # Shuffle the list of combinations of three elements
  44. random.shuffle(list_of_three)
  45.      
  46. [(2, 5, 15), (11, 13, 15), (3, 10, 15), (1, 6, 9), (1, 7, 8), ...]
  47.      
  48. import random
  49. fruits_in_store = ['apple','mango','orange','pineapple','fig','grapes','guava','litchi','almond']
  50. print('items available in store :')
  51. print(fruits_in_store)
  52. my_cart = []
  53. for i in range(4):
  54.     #selecting a random index
  55.     temp = int(random.random()*len(fruits_in_store))
  56.     # adding element at random index to new list
  57.     my_cart.append(fruits_in_store[temp])
  58.     # removing the add element from original list
  59.     fruits_in_store.pop(temp)  
  60. print('items successfully added to cart:')
  61. print(my_cart)
  62.      
  63. items available in store :
  64. ['apple', 'mango', 'orange', 'pineapple', 'fig', 'grapes', 'guava', 'litchi', 'almond']
  65. items successfully added to cart:
  66. ['orange', 'pineapple', 'mango', 'almond']
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top