random iteration in Python

You can use random.shuffle() to, well, shuffle a list: import random r = list(range(1000)) random.shuffle(r) for i in r: # do something with i By the way, in many cases where you’d use a for loop over a range of integers in other programming languages, you can directly describe the “thing” you want to iterate … Read more

Javascript: hiding prototype methods in for loop?

You can achieve desired outcome from the other end by making the prototype methods not enumerable: Object.defineProperty(Array.prototype, “containsKey”, { enumerable: false, value: function(obj) { for(var key in this) if (key == obj) return true; return false; } }); This usually works better if you have control over method definitions, and in particular if you have … Read more