How can I pair socks from a pile efficiently?

Sorting solutions have been proposed, but sorting is a little too much: We don’t need order; we just need equality groups. So hashing would be enough (and faster). For each color of socks, form a pile. Iterate over all socks in your input basket and distribute them onto the color piles. Iterate over each pile … Read more

Finding the index of an item in a list

>>> [“foo”, “bar”, “baz”].index(“bar”) 1 Reference: Data Structures > More on Lists Caveats follow Note that while this is perhaps the cleanest way to answer the question as asked, index is a rather weak component of the list API, and I can’t remember the last time I used it in anger. It’s been pointed out … Read more

What is RESTful programming?

REST is the underlying architectural principle of the web. The amazing thing about the web is the fact that clients (browsers) and servers can interact in complex ways without the client knowing anything beforehand about the server and the resources it hosts. The key constraint is that the server and client must both agree on … Read more