I am new to Python. I have a list:
sorted_x = [('pvg-cu2', 50.349189), ('hkg-pccw', 135.14921), ('syd-ipc', 163.441705), ('sjc-inap', 165.722676)]
I am trying to write a regular expression that will delete everything after the "-" and before the ",", that is, I need the same list as below:
[('pvg', 50.349189), ('hkg', 135.14921), ('syd', 163.441705), ('sjc', 165.722676)]
I wrote a regex as follows:
for i in range(len(sorted_x)): title_search = re.search('^\(\'(.*)-(.*)\', (.*)\)$', str(sorted_x[i]), re.IGNORECASE) if title_search: title = title_search.group(1) time = title_search.group(3)
But for this I need to create two new lists, and I do not want to change my original list. Can you suggest an easy way so that I can change my original list without creating a new list?
source share