iterating over list with one mising value

Dave Angel d at davea.name
Tue Feb 7 15:46:12 CET 2012


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




More information about the Python-list mailing list