This is a spin-off of one of my earlier questions
Problem statement: Given a number N and an arbitrary (but non-empty) set/string/list of characters E, return a random string of length N made up of the characters in E.
What is the most pythonic way of doing this? I can go with ''.join(( random.choice(E) for i in xrange(N) )), but I'm looking for a better way of doing this. Is there a built-in function in random or perhaps itertools that can do this?
Bonus points if:
- Fewer function calls
- Fitting into one line
- Better generalizability to any
NandE - Better run-time performance
PS: This question is really just me being a Python connoisseur (if I may call myself that) and trying to find elegant and artistic ways of writing code. The reason I mention this is because it looks a little bit like homework and I want to assure the SO community that it is not.