Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19960 > unrolled thread
| Started by | Dave Angel <d@davea.name> |
|---|---|
| First post | 2012-02-07 09:46 -0500 |
| Last post | 2012-02-07 10:34 -0600 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: iterating over list with one mising value Dave Angel <d@davea.name> - 2012-02-07 09:46 -0500
Re: iterating over list with one mising value Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-07 07:34 -0800
Re: iterating over list with one mising value Tim Chase <python.list@tim.thechases.com> - 2012-02-07 10:34 -0600
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-02-07 09:46 -0500 |
| Subject | Re: iterating over list with one mising value |
| Message-ID | <mailman.5502.1328625983.27778.python-list@python.org> |
On 02/07/2012 07:27 AM, Sammy Danso wrote: > Hello experts, > I am having trouble accessing the content of my list. > my list content has 2-pair value with the exception of one which has single value. here is an example ['a', 1, 'b', 1, 'c', 3, 'd'] > > I am unable to iterate through list to access invidual value pairs > > I get an error message saying ' the list should more than 1 value pairs'. I guess because 'd' has no value. How do I solve this problem? > > Your help would be much appreciated. > > Thanks > Sammy The real answer is to figure out how it gets into that state. Is the input file invalid? Or you have a device that sometimes skips one? But if you're stuck with the data in that list: If the list is of odd size, truncate it. Then your loop should not run into an uneven pair. Of course if you actually posted the code, or even the real and complete error message, we might be able to make other suggestions. -- DaveA
[toc] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2012-02-07 07:34 -0800 |
| Message-ID | <fcc877f5-2ae2-4cd5-9e73-727f4b3173d7@f30g2000yqh.googlegroups.com> |
| In reply to | #19960 |
On Feb 7, 8:46 am, Dave Angel <d...@davea.name> wrote: > On 02/07/2012 07:27 AM, Sammy Danso wrote:> Hello experts, > > I am having trouble accessing the content of my list. > > my list content has 2-pair value with the exception of one which has single value. here is an example ['a', 1, 'b', 1, 'c', 3, 'd'] First you need to explain why you're using a flat list when a number of other structures would be the better choice; like a list of tuples or a dict.
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2012-02-07 10:34 -0600 |
| Message-ID | <mailman.5504.1328632452.27778.python-list@python.org> |
| In reply to | #19964 |
On 02/07/12 09:34, Rick Johnson wrote: > On Feb 7, 8:46 am, Dave Angel<d...@davea.name> wrote: >> On 02/07/2012 07:27 AM, Sammy Danso wrote:> Hello experts, >>> I am having trouble accessing the content of my list. my >>> list content has 2-pair value with the exception of one >>> which has single value. here is an example ['a', 1, 'b', >>> 1, 'c', 3, 'd'] > > First you need to explain why you're using a flat list when a > number of other structures would be the better choice; like a > list of tuples or a dict. I'm not sure there's really a need for the OP to explain why...perhaps the data comes from an untrusted (or incompetent) source and the routine the OP is asking about is to *create* such a list-of-tuples or a dict. The more important question is what the user/app wants to do when such a case is encountered: do they want to ignore the unpaired value, or do they want to pad it with a default value? -tkc
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web