Given:
x = '1 (2,3), 4 (5)'
How would I get:
y = [(1,2),(1,3),(4,5)] ?
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Warning: this is fragile because of the regex-based parsing. (For instance, it assumes all your numbers are integers.) If your input is more flexible than I have assumed, you may wish to consider either generalising the regex or moving to a proper parsing library.
A neat use would be to put it in a function and change
printtoyield, to make it a generator.