data = 'This is pos:2 and i am going to interchange with pos:10'
Код ниже
val = [(i,v) for i,v in enumerate(data.split()) if ':' in v]
val
#[(2, 'pos:2'), (10, 'pos:10')]
x = list(zip(*val))
x
#[(2, 10), ('pos:2', 'pos:10')]
Мне нужно изменить 2,10 на 10,2 и вставить обратно в предложение
Ожидается
data = 'This is pos:10 and i am going to interchange with pos:2'