I’m turning a list into a set in Python, like so:
request.session['vote_set'] = set(request.session['vote_set'])
So I can easily do a if x in set lookup and eliminate duplicates. Then, when I’m done, I reconvert it:
request.session['vote_set'] = list(request.session['vote_set'])
Is there a better way to do this? Am I potentially doing something dangerous (or stupid)?
You’ll lose duplicates if you actually wanted them. If this is actually a list of “votes” as your naming suggests, you’d ‘lose’ some 🙂
why not just:
if you’re worried.
Although I have to wonder if that would be slower than just plain:
And ordering, as others have mentioned, would potentially (most likely) be lost.