rearrange text

Russell Blau russblau at
Thu Mar 3 18:46:14 CET 2005

"Daniel Skinner" <skinner.daniel at> wrote in message
news:1109777808.966606.9060 at
> If I have the following text
> var = '1,2,3,4'
> and I want to use the comma as a field delimeter and rearrange the
> fields to read
> '1,3,2,4'
> How would I accomplish this in python?

Well, it kind of depends on how you want to do the rearranging, whether the
data in the fields is always going to be numbers or could be some other kind
of object, etc.

In general, though, what you seem to be looking for is:

mylist = var.split(',')
newvar = ','.join(mylist)

I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.

More information about the Python-list mailing list