lundi 21 décembre 2015

Random list from list with no repetition

I created a random list from a source list, the problem is that it has an item that is repeated twice. I would like to have no repetition in my list. Here are my code and the output.

COLOR_INDEX = ['FF000000', 'FFFF0000', 'FF00FF00', 'FF0000FF',
               'FFFFFF00', 'FFFF00FF', 'FF00FFFF', 'FF800000', 'FF008000', 'FF000080',
               'FF808000', 'FF800080', 'FF008080', 'FFC0C0C0', 'FF808080', 'FF9999FF',
               'FF993366', 'FFCCFFFF', 'FF660066', 'FFFF8080', 'FF0066CC',
               'FFCCCCFF', 'FF000080', 'FFFF00FF', 'FFFFFF00', 'FF00FFFF', 'FF800080',
               'FF800000', 'FF008080', 'FF0000FF', 'FF00CCFF', 'FFCCFFFF', 'FFCCFFCC',
               'FFFFFF99', 'FF99CCFF', 'FFFF99CC', 'FFCC99FF', 'FFFFCC99', 'FF3366FF',
               'FF33CCCC', 'FF99CC00', 'FFFFCC00', 'FFFF9900', 'FFFF6600', 'FF666699',
               'FF969696', 'FF003366', 'FF339966', 'FF003300', 'FF333300', 'FF993300',
               'FF993366', 'FF333399', 'FF333333']


#import random function            
import random

#create a random list of colors.
color_lst= random.sample(COLOR_INDEX, len(label_list_for_col_header))
print color_lst

And here is the result:

['FF993366', 'FF333300', 'FFCCFFFF', 'FFCC99FF', 'FF993366', 'FFFF6600', 'FF339966', 'FF003366', 'FF000080', 'FF0000FF', 'FFFF00FF', 'FFFFFF99', 'FF800080', 'FF00CCFF', 'FF808080', 'FFFFCC99', 'FF333333', 'FF333399', 'FF99CC00', 'FFCCFFCC', 'FFFF99CC', 'FFFF9900', 'FF660066', 'FF008000', 'FFFF8080', 'FF99CCFF', 'FFFFCC00', 'FF003300', 'FF800000']




Aucun commentaire:

Enregistrer un commentaire