Skip to main content
deleted 106 characters in body
Source Link
Blender
  • 295.5k
  • 54
  • 447
  • 506

You can use random.sample() if you want to pluck out three distinct elements from the list (i.e. foo is never equal to bar, which might not be what you want):

foo, bar, baz = random.sample(l, 3)

I renamed your variable to l because list is a built-in type. Overriding it by accident won't be pretty.


Here's a sample (no bad pun intended):

>>> import random
>>> random.sample(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3)
['g', 'c', 'e']

You can use random.sample():

foo, bar, baz = random.sample(l, 3)

I renamed your variable to l because list is a built-in type. Overriding it by accident won't be pretty.


Here's a sample (no bad pun intended):

>>> import random
>>> random.sample(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3)
['g', 'c', 'e']

You can use random.sample() if you want to pluck out three distinct elements from the list (i.e. foo is never equal to bar, which might not be what you want):

foo, bar, baz = random.sample(l, 3)

I renamed your variable to l because list is a built-in type. Overriding it by accident won't be pretty.

Source Link
Blender
  • 295.5k
  • 54
  • 447
  • 506

You can use random.sample():

foo, bar, baz = random.sample(l, 3)

I renamed your variable to l because list is a built-in type. Overriding it by accident won't be pretty.


Here's a sample (no bad pun intended):

>>> import random
>>> random.sample(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3)
['g', 'c', 'e']