comparing data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick C
    New Member
    • Apr 2007
    • 54

    comparing data

    hey everyone,

    i'm going to be comparing data in a list. Just basic >= or <= type stuff.

    However, the list i have somtimes starts with 'n/a'. That is somtimes it starts like this:

    data = ['1.0', '2.0', '1.5']
    or
    data = ['n/a', '1.0', '2.0', '1.5']
    or
    data = ['n/a', 'n/a', '1.0', '2.0', '1.5']

    so i thought i could do something like this. so that I can start comparing actual numbers vs each other...

    Code:
    >>> for i in x:
    ... 	if i == 'n/a':
    ... 		x.remove(i)
    Should I just throw that bit in the code twice, back to back, in case i get a data list like the 3rd one (the oen w/ 2 n/a's) or does anyone have a more enlightened idea?

    thanks
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by Patrick C
    hey everyone,

    i'm going to be comparing data in a list. Just basic >= or <= type stuff.

    However, the list i have somtimes starts with 'n/a'. That is somtimes it starts like this:

    data = ['1.0', '2.0', '1.5']
    or
    data = ['n/a', '1.0', '2.0', '1.5']
    or
    data = ['n/a', 'n/a', '1.0', '2.0', '1.5']

    so i thought i could do something like this. so that I can start comparing actual numbers vs each other...

    Code:
    >>> for i in x:
    ... 	if i == 'n/a':
    ... 		x.remove(i)
    Should I just throw that bit in the code twice, back to back, in case i get a data list like the 3rd one (the oen w/ 2 n/a's) or does anyone have a more enlightened idea?

    thanks
    Here's a couple of options:[code=Python]>>> data = ['n/a', 'n/a', '1.0', '2.0', '1.5']
    >>> if 'n/a' in data:
    ... data = [item for item in data if item != 'n/a']
    ...
    >>> data
    ['1.0', '2.0', '1.5']
    >>> data = ['n/a', 'n/a', '1.0', '2.0', '1.5']
    >>> while 'n/a' in data:
    ... data.remove('n/a')
    ...
    >>> data
    ['1.0', '2.0', '1.5']
    >>> [/code]

    Comment

    Working...