I have a huge list in python that looks like this:
('foo','bar','foo/bar','foo1','bar/1')
Each value above demonstrates the character variety that the list contains - aplhanumeric plus slash. I need a way to turn that list into a list of tuples, like this:
(('foo','foo'),('bar','bar'),('foo/bar','foo/bar'),('foo1','foo1'),('bar/1','bar/1'))
So what better way to do this than Regex search and replace, right? (correct me if I'm wrong).
I am therefore trying to match anything between the quotes except for the commas, because technically, they are also between quotes. I used lookahead and lookbehind to match anything:
(?<=')(.*?)(?=')
But that only matches the values within the quotes and the commas. What I need is to match the value plus the quotes except the commas, and use a replacing regex to make the list look like the tuple above.
I can't do this by hand because the list is huge.
Any thoughts?
list, then you show us atuple, then you talk about parsing it with a regex, which implies that it's astr. Which is it?listofstrbut I need to convert it to atupleofstrtuple((element, element) for element in huge_list). Or, even more simple:tuple(zip(huge_list, huge_list)). Am I missing something?listto atuple, you just calltuple.