Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78676
| Date | 2014-10-03 19:21 -0700 |
|---|---|
| From | Larry Hudson <orgnut@yahoo.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Returning a List |
| References | <mailman.14573.1412336152.18130.python-list@python.org> |
| Message-ID | <mcydnV73o6E1xLLJnZ2dnUU7-LGdnZ2d@giganews.com> (permalink) |
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 -=-
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
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
csiph-web