Re: String to char and decimal number conversion

Discussion in 'Python' started by Chris Rebert, Jan 10, 2011.

  1. Chris Rebert

    Chris Rebert Guest

    On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . <> wrote:
    > Hello There,
    >
    >        I am from non IT field also new to python programming.Could you
    > please help me to solve the following problem?
    >
    > I have a list T1 with following format:
    >
    > T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']
    >
    > How do get the list elements without double quote in my output (T2).
    >
    > T2 =[ ' Field ' , ' 12.5 ', ' 2.5 ']


    How are you obtaining T1 in the first place?

    Cheers,
    Chris
    --
    http://blog.rebertia.com
     
    Chris Rebert, Jan 10, 2011
    #1
    1. Advertising

  2. Chris Rebert

    Alan Meyer Guest

    On 1/10/2011 6:02 PM, Chris Rebert wrote:
    > On Mon, Jan 10, 2011 at 2:44 PM, SANKAR .<> wrote:
    >> Hello There,
    >>
    >> I am from non IT field also new to python programming.Could you
    >> please help me to solve the following problem?
    >>
    >> I have a list T1 with following format:
    >>
    >> T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']
    >>
    >> How do get the list elements without double quote in my output (T2).
    >>
    >> T2 =[ ' Field ' , ' 12.5 ', ' 2.5 ']


    This will do it:
    ------------------------------------------------
    T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']
    T2 = []
    for t in T1:
    T2.append(t.replace('"', ''))
    ------------------------------------------------

    The "replace" function acts on each element in T1, replacing every
    double quote with nothing. We then append that to the new list T2.

    Alan
     
    Alan Meyer, Jan 11, 2011
    #2
    1. Advertising

  3. On Jan 11, 4:02 am, Chris Rebert <> wrote:
    > On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . <> wrote:
    > > Hello There,

    >
    > >        I am from non IT field also new to python programming.Could you
    > > please help me to solve the following problem?

    >
    > > I have a list T1 with following format:

    >
    > > T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']

    >
    > > How do get the list elements without double quote in my output (T2).

    >
    > > T2 =[ ' Field ' , ' 12.5 ', ' 2.5 ']

    >
    > How are you obtaining T1 in the first place?
    >
    > Cheers,
    > Chris
    > --http://blog.rebertia.com



    You can also do it like :
    T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']
    T2 = [t.replace('"', '') for t in T1]

    This seems to me a more better and fast code ;)


    Davish
     
    Davish Bhardwaj, Jan 11, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lovecreatesbeauty
    Replies:
    1
    Views:
    1,071
    Ian Collins
    May 9, 2006
  2. Replies:
    14
    Views:
    1,047
    Simon Biber
    Nov 16, 2006
  3. Replies:
    2
    Views:
    829
  4. Ven
    Replies:
    3
    Views:
    1,334
  5. Pete Sammet
    Replies:
    5
    Views:
    171
    Peter J. Holzer
    Jun 7, 2010
Loading...

Share This Page