Ensuring random order for iteration over Set Python -
i iterating on set in python. in application prefer iteration in random order each time. see same order each time run program. isn't fatal there way ensure randomized iteration on set?
use random.shuffle
on list of set.
>>> import random >>> s = set('abcdefghijklmnopqrstuvwxyz') >>> in range(5): #5 tries l = list(s) random.shuffle(l) print ''.join(l) #iteration nguoqbiwjvelmxdyazptcfhsrk fxmaupvhboclkyqrgdzinjestw bojweuczdfnqykpxhmgvsairtl wnckxfogjzpdlqtvishmeuabry frhjwbipnmdtzsqcaguylkxove
Comments
Post a Comment