4 ms·
I didn't mean to imply that lacking a sorted set datatype wasn't a pain in the ass; I was pointing out that the lack of multiple set implementations is a tradeo
by pjscott 16y ago
I didn't mean to imply that lacking a sorted set datatype wasn't a pain in the ass; I was pointing out that the lack of multiple set implementations is a tradeoff that we make for all built-in datatypes that could support other operations but don't. (Personally, I would love to have the ability to pick a random element from a set. That would be great.)
By the way, in case anybody was wondering, here is a (relatively inefficient) way of making a sorted set in python:
http://code.activestate.com/recipes/576694/ http://code.activestate.com/recipes/576694/
- silvertab 16y agoCouldn't you just do the following? from random import choice choice(list(myset)) (I'm guessing you'd want to do it without having to convert it to a list first?)
- pjscott 16y agoThat's what I ended up doing, but this was happening with a very large set, right in an inner loop. Luckily this was running in batch mode, so I could go get lunch or something instead of taking the time to make it faster.