List question from newby

Discussion in 'Python' started by GMAN1941, Jul 25, 2013.

  1. GMAN1941

    GMAN1941

    Joined:
    Apr 2, 2013
    Messages:
    4
    Likes Received:
    0
    Location:
    huntsville, al
    using 2.5 . i have the following data from a field in a database:
    2,870,728,641
    the code is:
    for line in reader:
    preds.append(line[-1])
    # what i get is: ['2,870,728,641']
    # when i use join
    linklist=string.join(preds)
    predlist.append(linklist)
    # i get the same thing

    what i need is:
    [2,870,728,641] without the beginning & ending quote so i can i can iterate each as a separte value/word:
    preds[0] renders 2, pres[1] renders 870 etc

    or
    ['2','870','728','641'] to get separate words also

    i can't seem to find the answer

    thanks
    GMAN
     
    Last edited: Jul 25, 2013
    GMAN1941, Jul 25, 2013
    #1
    1. Advertisements

  2. GMAN1941

    lupulcelbun

    Joined:
    May 15, 2015
    Messages:
    1
    Likes Received:
    0
    If 2.5 is anything like 2.6 then the quotes simply mean that the information is stored in a String and not a number.
    Note the way python prints out stuff - with and without quotes.

    Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> my_strings=['1','2']
    >>> my_numbers=[1,2]
    >>> my_strings
    ['1', '2']
    >>> my_numbers
    [1, 2]
    >>> '1' == 1
    False
    >>> int('1') == 1
    True
    >>> '1' == str(1)
    True
    >>> for stuff in my_numbers:
    ... print type(stuff)
    ... print stuff
    ...
    <type 'int'>
    1
    <type 'int'>
    2
    >>> for stuff in my_strings:
    ... print type(stuff)
    ... print stuff
    ...
    <type 'str'>
    1
    <type 'str'>
    2
    >>>
     
    lupulcelbun, May 15, 2015
    #2
    1. Advertisements

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. Hermann W Ehlers

    Newby question

    Hermann W Ehlers, May 2, 2004, in forum: ASP .Net
    Replies:
    12
    Views:
    959
    Matt Berther
    May 5, 2004
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    ASP.NET easy newby question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Nov 22, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    740
    Kevin Spencer
    Nov 23, 2004
  3. John Baker
    Replies:
    3
    Views:
    455
    Kevin Spencer
    Feb 8, 2005
  4. John Baker

    Rephrase of Newby Question!

    John Baker, Feb 8, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    787
    Michael C#
    Feb 9, 2005
  5. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    996
    Iain Norman
    Feb 16, 2005
  6. Bruno Alexandre

    a newby question

    Bruno Alexandre, May 2, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    559
    Bruno Alexandre
    May 2, 2005
  7. Eelco Hoekema

    [Newby question] List comprehension

    Eelco Hoekema, Aug 6, 2004, in forum: Python
    Replies:
    7
    Views:
    587
    Eelco Hoekema
    Aug 6, 2004
  8. Batista, Facundo

    RE: [Newby question] List comprehension

    Batista, Facundo, Aug 6, 2004, in forum: Python
    Replies:
    8
    Views:
    424
    Peter Hansen
    Aug 6, 2004
Loading...