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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.