Steven D'Aprano wrote:
> On Mon, 06 Nov 2006 13:03:55 +, Tuomas wrote:
>
>
>>If you read the whole chain you find out what we were talking of.
>
>
> I had already read the whole thread, and I've read it again in case I
> missed something the first time, and I still have no idea why you thin
On Mon, 06 Nov 2006 13:03:55 +, Tuomas wrote:
> If you read the whole chain you find out what we were talking of.
I had already read the whole thread, and I've read it again in case I
missed something the first time, and I still have no idea why you think
you need to do this. You explain *wha
Steve Holden wrote:
> Suppose you did actually want to do this you have chosen about the worst
> possible way: the use of global variables to condition function
> execution is a sure way to get into trouble. Consider if somebody else
> want to use your function: they also have to set a global in
Tuomas wrote:
> Steven D'Aprano wrote:
>
>>On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote:
>>
>>
>>
>>>Thanks. My solution became:
>>>
>>>
>>def flattern(arg):
>>>
>>>... result = []
>>>... for item in arg:
>>>... if isinstance(item, (list, tuple)):
>>>... result.
Steven D'Aprano wrote:
> On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote:
>
>
>>Thanks. My solution became:
>>
>> >>> def flattern(arg):
>>... result = []
>>... for item in arg:
>>... if isinstance(item, (list, tuple)):
>>... result.extend(flattern(item))
>>...
Dennis Lee Bieber wrote:
> On Sun, 05 Nov 2006 22:51:00 GMT, Tuomas <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>
>>>
>>
>>I fylly agree with tis: "Typically, the responsibility should be on the
>>CALLER, not the CALLED..". I just don't know how to unpack *arg for
>>ca
On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote:
> Thanks. My solution became:
>
> >>> def flattern(arg):
> ... result = []
> ... for item in arg:
> ... if isinstance(item, (list, tuple)):
> ... result.extend(flattern(item))
> ... else:
> ... resu
Dennis Lee Bieber wrote:
> On Sun, 05 Nov 2006 17:42:30 GMT, Tuomas <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>
>
>>I am looking a shorter way to do the above in the case:
>>
>>def g(*arg):
>> return arg
>>
>>def f(*arg):
>> return g(arg)
>>
>>How can g know if
Stargaming wrote:
> Either you take one of the snippets here:
> http://aspn.activestate.com/ASPN/search?query=flattenĀ§ion=PYTHONCKBK&type=Subsection
>
>
> or just use arg[0] clever (as mentioned a few times in this thread).
Thanks. My solution became:
>>> def flattern(arg):
... result = [
Tuomas schrieb:
> Tuomas wrote:
>
>> def g(*arg):
>> return arg
>>
>> def f(*arg):
>> return g(arg)
>>
>> How can g know if it is called directly with (('foo', 'bar'),) or via
>> f with ('foo', 'bar'). I coud write in f: return g(arg[0], arg[1]) if
>> I know the number of arguments, but
Tuomas wrote:
> def g(*arg):
> return arg
>
> def f(*arg):
> return g(arg)
>
> How can g know if it is called directly with (('foo', 'bar'),) or via f
> with ('foo', 'bar'). I coud write in f: return g(arg[0], arg[1]) if I
> know the number of arguments, but what if I don't know that in
Steven D'Aprano wrote:
> You could write something like this:
>
> def g(*arg):
> # Detect the special case of a single tuple argument
> if len(arg) == 1 and type(arg[0]) == tuple:
> return arg[0]
> else:
> return arg
>
> but now tuple arguments are treated differently
On Sun, 05 Nov 2006 15:26:58 +, Tuomas wrote:
> >>> def g(*arg):
> ... return arg
> ...
> >>> g('foo', 'bar')
> ('foo', 'bar')
> >>> # seems reasonable
The function g:
- takes the arguments 'foo' and 'bar'
- collects them in a tuple named 'arg' = ('foo', 'bar')
- returns the tuple name
Tuomas schrieb:
> >>> def g(*arg):
> ... return arg
> ...
> >>> g('foo', 'bar')
> ('foo', 'bar')
> >>> # seems reasonable
> ...
> >>> g(g('foo', 'bar'))
> (('foo', 'bar'),)
> >>> # not so good, what g should return to get rid of the outer tuple
>
> TV
Use the following then:
>>> g(*g('fo
Diez B. Roggisch wrote:
> Tuomas schrieb:
>
>> >>> def g(*arg):
>> ... return arg
>> ...
>> >>> g('foo', 'bar')
>> ('foo', 'bar')
>> >>> # seems reasonable
>> ...
>> >>> g(g('foo', 'bar'))
>> (('foo', 'bar'),)
>> >>> # not so good, what g should return to get rid of the outer tuple
>
>
Tuomas schrieb:
> >>> def g(*arg):
> ... return arg
> ...
> >>> g('foo', 'bar')
> ('foo', 'bar')
> >>> # seems reasonable
> ...
> >>> g(g('foo', 'bar'))
> (('foo', 'bar'),)
> >>> # not so good, what g should return to get rid of the outer tuple
g(*g('foo', 'bar'))
* and ** are the syme
>>> def g(*arg):
... return arg
...
>>> g('foo', 'bar')
('foo', 'bar')
>>> # seems reasonable
...
>>> g(g('foo', 'bar'))
(('foo', 'bar'),)
>>> # not so good, what g should return to get rid of the outer tuple
TV
--
http://mail.python.org/mailman/listinfo/python-list
17 matches
Mail list logo