cannot pass a variable from a function

Doug Jordan djordan8 at houston.rr.com
Fri Jun 18 14:59:11 EDT 2004


this seems to work only if c in def(c) is a list.  I have a tuple of tuples.
I need to operate on one of the members of adata pair and return a new tuple
of tuples to be used later in the program.

if I use the following,  it only returns 1 value.
tup1=((1,3),(2,5),(3,9))
def NewFctn(c):
    for a,b in c:
        v=b*9
        return v
y=NewFctn(tup1)

what I need is to return v as a tuple of tuples to be used later in the
program.  How do I do this.  I cannot find any information on this.
This is needed because I need to perform some operations on the second
member of data pairs stored as a tuple of tuples.  This is needed to post
process output from a commercial program(ABAQUS)
ie.
Output variable might contain
((t1,F1),(t2,F2)..(tn,Fn))  I want to  perform operations on Fi
Thanks
Sorry about all the confusion
Doug
"Porky Pig Jr" <porky_pig_jr at my-deja.com> wrote in message
news:56cfb0e3.0406162048.5eeba56 at posting.google.com...
> "Doug Jordan" <djordan8 at houston.rr.com> wrote in message
news:<m54Ac.3645$4g1.791 at fe2.texas.rr.com>...
> > I am fairly new to Python.  This should be an easy answer but I cannot
get
> > this to work.  The code is listed below.  I know how to do this in C,
> > Fortran, and VB but it doesn't seem to work the same way here.
> > I would appreciate any help.
> >
> > #try this to pass a list to a function and have the function return
> > #a variable
> > #this works
> > list=[1,4,6,9]
> > def fctn(c):
> >     for h in c:
> >         q=h*80
> >         print q
>
> You know, I am also new to Python, and fairly well versed in C, but
> don't you think  that the following function:
>
> > #function suppose to return variable
> > def fctn2(c):
> >     for h in c:
> >         q=h*80
> >         return q
>
> will return whatever it gets on a very first iteration so it will
> return a scalar 1*80 rather than list I assume you are trying to
> return.
> You probably need something like this:
> def fctn2(c):
>     return [h * 80 for h in c]
>
>
>
> Once again, you didn't make it quite clear what is that exaclty you
> are trying to return, so I assume you are trying to return a list,
> rather than scalar.





More information about the Python-list mailing list