Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54365 > unrolled thread

Re: Remove \n, " " from tuple.

Started byDave Angel <davea@davea.name>
First post2013-09-18 09:03 +0000
Last post2013-09-18 09:03 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Remove \n, " " from tuple. Dave Angel <davea@davea.name> - 2013-09-18 09:03 +0000

#54365 — Re: Remove \n, " " from tuple.

FromDave Angel <davea@davea.name>
Date2013-09-18 09:03 +0000
SubjectRe: Remove \n, " " from tuple.
Message-ID<mailman.111.1379495030.18130.python-list@python.org>
On 18/9/2013 01:12, Venkat Addala wrote:

> Hi all,
>
> I have a tuple in this format, which is retrived using MySQLdb, now i want
> to remove \n and extra spaces in this.
>
> 13L, 'ssDsC', 'CEs5s1, DsC', 'srylscetsmight\nghtscetylsse', '3', '3q25.1',
> 151531861L, 151546276L, '+', '1 kjafhkfhlad\fdfdsdf ghtscetylsse \ncontends
> the sctivity of dsfdk srylsmine N-scetyltrsnsfersse thst scts ss s cstslyst
> inbiotrsnsformstion fghjfg for srylsmine snd bvhghbh smine csrcinogens.
> Bgskjdg in ssDsC dfkdkdf in bresst snd prostrste csncer.', '', 'Msdhurs
> \nsgdfgssssvslingegowds', dstetime.dste(2013, 6, 14), None
>

A tuple is immutable, so it cannot be done.

However, you can create a new tuple.  Easiest way is probably to convert
it to a list, process any strings in the list, and convert it back.


def convert(mylist):
    res = []
    for item in mylist:
        if isinstance(item, str):
            item = ............    to be filled in
        res.append(item)
    return res


mytuple = .....
temp = list(mytuple)
mytuple = tuple(convert(temp))


-- 
DaveA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web