Initially, I wasn’t sure whether this was the appropriate place for this question, but after reading through the FAQ I feel fairly confident the topic is acceptable…. Furthermore I wasn’t sure if this would be classified as a particular type of problem (eg. a knapsack problem), thus, the title is rather vague. I’m sorry for that. Anyways. As both practice
Tag: algorithm
Finding the most frequent character in a string
I found this programming problem while looking at a job posting on SO. I thought it was pretty interesting and as a beginner Python programmer I attempted to tackle it. However I feel my solution is quite…messy…can anyone make any suggestions to optimize it or make it cleaner? I know it’s pretty trivial, but I had fun writing it. Note:
How do I generate all permutations of a list?
How do I generate all the permutations of a list? For example: Answer Use itertools.permutations from the standard library: Adapted from here is a demonstration of how itertools.permutations might be implemented: A couple of alternative approaches are listed in the documentation of itertools.permutations. Here’s one: And another, based on itertools.product: