> On 05/10/16 10:03, rakesh sharma wrote: >> Hi all >> >> I have a string of pattern ({A,BC},{(A,B),(B,C)(C,A)}. >
On Wed, Oct 5, 2016 at 3:14 AM, Alan Gauld via Tutor <tutor@python.org> wrote: > Until we understand the data better we can't be sure > a regex is the best solution. Yes, I agree with Alan: we need to know more about the problem. You've given one example. Do you have a few more examples to give? Why is your input a string, and not a structured object? Where does this input come from? Generalizing a solution from an example set of size one is trivially easy. It doesn't need regexes or anything: it just needs a simple string comparison: ########################################### def solution(input): if input == "({A,BC},{(A,B),(B,C)(C,A)}": return "{A,B,C}" ########################################### You might think that I'm joking. This is a "ha, ha, just serious" sort of thing. In fact, this is exactly the first implementation I would write if I were writing in test-driven-development mode. It forces me to write good test cases that actually exercise the solution and to make sure I don't cheat like this. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor