473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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...

Expand|Select|Wrap|Line Numbers
  1. >>> for i in x:
  2. ...     if i == 'n/a':
  3. ...         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
Oct 3 '07 #1
1 1303
bvdet
2,851 Expert Mod 2GB
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...

Expand|Select|Wrap|Line Numbers
  1. >>> for i in x:
  2. ...     if i == 'n/a':
  3. ...         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:
Expand|Select|Wrap|Line Numbers
  1. >>> data = ['n/a', 'n/a', '1.0', '2.0', '1.5']
  2. >>> if 'n/a' in data:
  3. ...     data = [item for item in data if item != 'n/a']
  4. ...     
  5. >>> data
  6. ['1.0', '2.0', '1.5']
  7. >>> data = ['n/a', 'n/a', '1.0', '2.0', '1.5']
  8. >>> while 'n/a' in data:
  9. ...     data.remove('n/a')
  10. ...     
  11. >>> data
  12. ['1.0', '2.0', '1.5']
  13. >>> 
Oct 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
2
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
1
by: Will Chamberlain | last post by:
I just created an application that displays data from 2 sources in a datagrid. There are 2 repeaters nested in the datagrid (probably not the best idea). The whole purpose of this application is to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.