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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -