rearrange text

Russell Blau russblau at hotmail.com
Thu Mar 3 12:46:14 EST 2005


"Daniel Skinner" <skinner.daniel at gmail.com> wrote in message
news:1109777808.966606.9060 at o13g2000cwo.googlegroups.com...
> 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(',')
rearrange(mylist)
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