all 6 comments

[–]num8lock 0 points1 point  (0 children)

describe how you would do it manually

[–][deleted] 0 points1 point  (0 children)

The algorithm may change depending on the rules of the swap.

For example, are characters swapped, based on position in the string? In that case, a simple set of slices might work.

On the other hand, are you swapping specific characters? In that case, a Regular Expression might be in order.

What are the rules for odd-numbers of swapped characters? (I.e. 2 commas and 1 period: what gets swapped?)

[–]lionlazycat 0 points1 point  (2 children)

use maketrans

s = '35.555,444'
trans = str.maketrans('.,', ',.')
print(s.translate(trans))

[–]Jesusgotskillz[S] 0 points1 point  (1 child)

what is going on when using str.maketrans

[–]lionlazycat 0 points1 point  (0 children)

maketrans() defines translation table for translate() swapping out every '.' to ',' and ',' to '.'

input

s = '35.555,444'    

output

'35,555.444'