Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string.': 0.04; 'python': 0.08; 'appreciated,': 0.09; 'from:addr:python': 0.09; 'lines:': 0.09; 'subject:anyone': 0.09; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply-to:addr:python-list': 0.16; 'wrote:': 0.16; 'have:': 0.18; 'subject:not': 0.21; 'subject:help': 0.21; 'subject:list': 0.21; 'header:In-Reply- To:1': 0.22; 'complain': 0.23; 'numeric': 0.23; 'string': 0.24; '(in': 0.26; 'compare': 0.28; 'script': 0.28; 'print': 0.29; 'anyone': 0.31; 'list': 0.32; 'thanks': 0.32; 'initial': 0.32; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.33; 'received:84': 0.34; 'numbers.': 0.34; 'reply-to:addr:python.org': 0.34; '...': 0.35; 'help,': 0.35; 'checks': 0.36; 'instead.': 0.36; 'skip:" 10': 0.36; 'list,': 0.37; 'but': 0.37; 'subject:can': 0.37; 'could': 0.37; 'subject: !': 0.38; 'initially': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'data': 0.40; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'subject:thanks': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=Xb8LPfF5 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=FFsdPcU1_MIA:10 a=FZTZVutFavIA:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=kJSABN0o_6Qj0LcFTA4A:9 a=aqhHX4JZqzAaV_-pMQUA:7 a=wPNLvfGTeEIA:10 a=N_UK1RvYk0cBzO9w:21 a=1eFN-N1NqifCluAw:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Wed, 01 Feb 2012 01:06:15 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: the script can not go through all the list, anyone could help, would be highly appreciated, thanks a lot ! References: <244c26a3.9ac.13536369f41.Coremail.crazy_pipi_lu@163.com> In-Reply-To: <244c26a3.9ac.13536369f41.Coremail.crazy_pipi_lu@163.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 68 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328058336 news.xs4all.nl 6915 [2001:888:2000:d::a6]:36315 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19672 On 01/02/2012 00:00, Para wrote: > the script can not go through all the list, anyone could help, would be > highly appreciated, thanks a lot ! > > output: > initial 7 lines: > [9379, 'G', '0.1830'] > [9378, 'G', '0.1752'] > [9377, 'G', '0.1929'] > [9375, 'G', '0.1950'] > [9370, 'G', '0.1872'] > [937, 'G', '0.1931'] > [93, 'G', '0.1974'] > processing: > code_K = 93 rate_K = -1 len_K = 1 len_G = 7 > code_K = 93 rate_K = 0.1830 code_G = 9379 rate_G = 0.1830 > code_K = 93 rate_K = 0.1929 code_G = 9377 rate_G = 0.1929 > code_K = 93 rate_K = 0.1929 code_G = 9370 rate_G = 0.1872 > code_K = 93 rate_K = 0.1974 code_G = 93 rate_G = 0.1974 > final 3 lines: > [9378, 'G', '0.1752'] > [9375, 'G', '0.1950'] > [937, 'G', '0.1931'] > > > code: > ...... # read data from .csv > print "initial", len(list_G), "lines:" > for row_G in list_G: > print row_G > > print "processing:" > for row_K in list_K: > code_K = str(row_K[0]) > rate_K = -1 > len_K = len(list_K) > len_G = len(list_G) > print "code_K =", code_K, "rate_K =", rate_K, "len_K =", len_K, "len_G =", len_G > for row_G in list_G: > code_G = str(row_G[0]) > rate_G = str(row_G[2]) > if re.match(code_K, code_G): > if rate_K < rate_G: > rate_K = rate_G > print "code_K =", code_K, "rate_K =", rate_K, "code_G =", code_G, > "rate_G =", rate_G > list_G.remove(row_G) > > print "final", len(list_G), "lines:" > for row_G in list_G: > print row_G rate_K is initially a number (rate_K = -1), but rate_G is a string. If you want to compare numeric values, make sure that they are both numbers. (In Python 3 it will complain if you say x < y when one of them is a string and the other is a number; in Python 2 it will return a consistent but arbitrary result.) The re.match(code_K, code_G) checks whether code_G start with code_K. It is better to use code_G.startswith(code_K) instead. Also, you have: for row_G in list_G: ... list_G.remove(row_G) Don't add or remove items in a list over which you are iterating.