vendredi 15 février 2019

Counting elements in a list with a given number of elements

I want to create two lists. The first has x elements, 'Name n', where (1 <= n <= x).

I would like to second list to randomly assign 'Lucky' to one of the x elements and 'Not Lucky' to rest of the elements.

When x=4, for example:

names = ['Name 1', 'Name 2', 'Name 3', 'Name 4']
luck = ['Not Lucky', 'Lucky', 'Not Lucky', 'Not Lucky']

I want to use a list comprehension for both, and something from random luck=[], but am stuck on how to implement it. Any ideas?




Aucun commentaire:

Enregistrer un commentaire