Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49417
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!news.skynet.be!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'matches': 0.07; 'suppose': 0.07; 'string': 0.09; 'assuming': 0.09; 'correct,': 0.09; 'friday,': 0.09; 'iterate': 0.09; 'logic': 0.09; 'itself.': 0.14; 'buggy': 0.16; 'comma': 0.16; 'csv': 0.16; 'field[0]': 0.16; 'implies': 0.16; 'issue?': 0.16; 'loop.': 0.16; 'received:74.208.4.195': 0.16; 'substring': 0.16; 'index': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'advance.': 0.19; 'file,': 0.19; 'separate': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'interpret': 0.24; 'parse': 0.24; 'url:moin': 0.24; 'compare': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'reaches': 0.30; 'subject:list': 0.30; "i'm": 0.30; 'lines': 0.31; 'url:wiki': 0.31; 'file': 0.32; 'open': 0.33; 'up.': 0.33; 'url:python': 0.33; 'maybe': 0.34; 'could': 0.34; 'test': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'done,': 0.36; 'false': 0.36; 'module.': 0.36; 'sequence': 0.36; 'method': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'too': 0.37; 'two': 0.37; 'list': 0.37; 'being': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'dave': 0.60; 'break': 0.61; 'mentioned': 0.61; 'entire': 0.61; "you're": 0.61; "you'll": 0.62; 'complete': 0.62; 'show': 0.63; 'map': 0.64; 'taking': 0.65; 'between': 0.67; 'received:74.208': 0.68; 'said:': 0.68; 'helping': 0.70; 'fields,': 0.84; 'out!': 0.84; '(i)': 0.91; 'items,': 0.91; '2013': 0.98 |
| Date | Sat, 29 Jun 2013 09:44:55 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: indexerror: list index out of range?? |
| References | <8b12635e-c3e9-49b2-b3fa-792559088821@googlegroups.com> <c6642bec-58b1-4db2-bad9-6f85cb3cf5c6@googlegroups.com> |
| In-Reply-To | <c6642bec-58b1-4db2-bad9-6f85cb3cf5c6@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:lxH1+1sEAz6pJ0fdDRflPxJbsVyYGlEQ+8JEqW5RJ2r bsbekPDJn4yggW2pFjK10lGv3504H3YG5BGksFpxtRX3KnVDe3 oFxUZ/EVANUEuD63OF7B2hyaERkdpyLzsOayi63sQtkf/XUdso kgatFtQSdIQSOQjbpRf9hUeXjB7qdw56t45BytGfK20XfH2F1n L6H+UZk5gI4rFMr4o+OOM7cyKTSASVgNQwqJQqLaOWZy22CUL/ +IyBBraHaEQMHoI796JbilfFHwQQoPPqwPoLYuYqrUeNNXRCMT Z74eql6ZCXEZnrgj/lZrU6mT+O1ivt64y5H4HorJ1JrsYgdFcF D0DVnwZ3XdJUWCx6GZg4= |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3987.1372513508.3114.python-list@python.org> (permalink) |
| Lines | 62 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1372513508 news.xs4all.nl 15866 [2001:888:2000:d::a6]:36612 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:49417 |
Show key headers only | View raw
On 06/28/2013 11:35 PM, Titiksha wrote:
> On Friday, June 28, 2013 8:20:28 PM UTC-5, Titiksha wrote:
>>
<SNIP double-spaced nonsense>
>>
>> m=['631138', '601034', '2834', '2908', '64808']
>>
<SNIP more double-spaced nonsense>
>>
>>
>>
>> ['LAKEFLD 3227,631138\n', 'NOBLES 3013,601034\n']
>>
>>
Since you're using the arrogant and buggy GoogleGroups, this
http://wiki.python.org/moin/GoogleGroupsPython.
>>
>>
>> I see the line,a being correct but print (i) does not show up after 2. and index error comes up. I am too confused now. Please guide.
>>
>> Thanks in advance.
>
> Thanks for helping out!
> Dave you mentioned about false matches in case of string in m is substring of line. How do I manage that issue? Is there any other method I should look into?
Suppose one of the items in m were '1234', and suppose one of the lines
in the file be
'HARMONY 12,441234913'
Your current logic would consider it a match, and I'm assuming that
would be a false match.
To fix that, you need to parse the line from the file, and separate it
into fields, one of which needs to exactly match 1234.
You call it a csv file, and if it were, you could just use the csv
module. But there's no comma between LAKEFLD and 3227, so the line
would be considered to have two fields. If that's correct, then you're
golden. Just use csv to get the fields, and compare m[i] == field[1]
rather than m[i] in line.
>
> What I am looking to do is..I have a list of m which I need to map in the same sequence to the ALL_BUSES_FINAL file and get the entire line which has the string in m.I want to iterate through all the lines in ALL_BUSES_FINAL to match the all strings in m.
>
Any way I can interpret those sentences, it contradicts itself. Could
you just post the complete assignment, without paraphrasing?
Taking an individual phrase of what you said: "same sequence" implies
you do NOT want to re-open the file multiple times. So move the open
outside of the while loop. Add a test and a break after incrementing i,
since you'll quit looking once you have a match for all the items, and
you'll know that when i reaches the len of m.
Hopefully you'll know how to get the single line out of a when you're
done, maybe by concatenating field[0] of each line.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
indexerror: list index out of range?? Titiksha Joshi <joshi.titiksha90@gmail.com> - 2013-06-28 18:20 -0700
Re: indexerror: list index out of range?? Chris Angelico <rosuav@gmail.com> - 2013-06-29 11:53 +1000
Re: indexerror: list index out of range?? Dave Angel <davea@davea.name> - 2013-06-28 21:58 -0400
Re: indexerror: list index out of range?? Titiksha <joshi.titiksha90@gmail.com> - 2013-06-28 20:35 -0700
Re: indexerror: list index out of range?? Dave Angel <davea@davea.name> - 2013-06-29 09:44 -0400
Re: indexerror: list index out of range?? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-29 15:30 +0100
Re: indexerror: list index out of range?? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-29 16:52 +0100
Re: indexerror: list index out of range?? Robert Kern <robert.kern@gmail.com> - 2013-07-01 09:45 +0100
Re: indexerror: list index out of range?? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-01 12:30 +0000
csiph-web