Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78645 > unrolled thread

Returning a List

Started byShiva <shivaji_tn@yahoo.com>
First post2014-10-03 11:35 +0000
Last post2014-10-03 19:21 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Returning a List Shiva <shivaji_tn@yahoo.com> - 2014-10-03 11:35 +0000
    Re: Returning a List Larry Hudson <orgnut@yahoo.com> - 2014-10-03 19:21 -0700

#78645 — Returning a List

FromShiva <shivaji_tn@yahoo.com>
Date2014-10-03 11:35 +0000
SubjectReturning a List
Message-ID<mailman.14573.1412336152.18130.python-list@python.org>
Hi All,

I might be doing something really silly here, but I can't seem to spot it:

def front_x(words):
  b=[]
  c=[]
  for a in words:
     if a[0] == 'x':
         b.append(a)
     else:
         c.append(a)

  b = sorted(b)
  c = sorted(c)
  d= b+c
  print('d = ',d)

  #return b+c
  return d

front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa'])



Why is return d or return b+c not returning anything??

The d's value is confirmed by the print statement.

Thanks,
Shiva.

[toc] | [next] | [standalone]


#78676

FromLarry Hudson <orgnut@yahoo.com>
Date2014-10-03 19:21 -0700
Message-ID<mcydnV73o6E1xLLJnZ2dnUU7-LGdnZ2d@giganews.com>
In reply to#78645
On 10/03/2014 04:35 AM, Shiva wrote:
> Hi All,
>
> I might be doing something really silly here, but I can't seem to spot it:
>
> def front_x(words):
>    b=[]
>    c=[]
>    for a in words:
>       if a[0] == 'x':
>           b.append(a)
>       else:
>           c.append(a)
>
>    b = sorted(b)
>    c = sorted(c)
>    d= b+c
>    print('d = ',d)
>
>    #return b+c
>    return d
>
> front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa'])
>
>
>
> Why is return d or return b+c not returning anything??
>
> The d's value is confirmed by the print statement.
>
> Thanks,
> Shiva.
>
Works fine for me...

For a quickie test, I copy/pasted this code into Idle, and it works.

I suspect you are trying to run this as a script -- but remember, when running interactively 
(directly in Python or in Idle) the return values are displayed automatically.  This is NOT true 
when running as a program, you have to specifically print the return values (or save them in a 
variable to access them later).  Change your calling line to:

print(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']))

      -=- Larry -=-

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web