[Tutor] small problem with lists/tuples

Jeff Shannon jeff at ccvcorp.com
Mon Sep 29 13:56:36 EDT 2003


Thomi Richards wrote:

> I have a function which returns some data in different forms. for example:
> sometimes, it will return:
> 
> ['data']
> 
> or:
> 
> [['data']]
> 
> or even:
> 
> ([['data']])
> 
> what I'm trying to do, is "unpack" the duples, until i get to the actual data 
> inside. 

Any chance you can change what the original function returns?  It 
seems to me that a function that may return single-item nested lists 
is confusing, and my inclination would be to make the function return 
something sensible, instead of trying to make sense of the mess that 
it currently returns.  I'm not sure *why* this function might have 
variable levels of nesting, especially since it seems that you expect 
all of them to have only a single item, but I'd bet that it'd be 
easier to attack this problem by not building the extra levels than by 
stripping them off later.

Of course, it may be that the source of this function is outside of 
your control, in which case you have little choice.  But it seems to 
me that the earlier you eliminate the confusing extra levels, the better.

If you *do* have access to the source code for the function, post that 
here and we'll see what we can do to simplify it and normalize its output.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Tutor mailing list