iterating over list with one mising value
python.list at tim.thechases.com
Tue Feb 7 17:34:32 CET 2012
On 02/07/12 09:34, Rick Johnson wrote:
> On Feb 7, 8:46 am, Dave Angel<d... at 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?
More information about the Python-list