Hey, no problem. One thing to keep in mind about your solution: you're returning a tuple now, not a list. A tuple is immutable once formed, so if you get errors when trying to modify the return value, that's why. Generally you want to match the data structure you use to the concept they're supposed to be modeling, so if your data is mutable and you only want to return the first three elements, you want to use a slice: return my_list[:3].<div>
<br></div><div>Cheers,<br clear="all"><div>Nick</div><br>
<br><br><div class="gmail_quote">On Tue, Dec 27, 2011 at 7:53 PM, Mike Bean <span dir="ltr"><<a href="mailto:beandaemon@gmail.com">beandaemon@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
OK, I think I got this:<br><br>def test_function():<br> my_array=[1,2,3]<br> return(my_array[0], my_array[1], my_array[2])<br><br>for x in test_function():<br> print(x)<br><br>Thank you Nick!<br><font color="#888888"><br>
Bean<br><br></font><div class="gmail_quote"><div class="im">
On Tue, Dec 27, 2011 at 6:38 PM, Nick Pascucci <span dir="ltr"><<a href="mailto:npascut1@gmail.com" target="_blank">npascut1@gmail.com</a>></span> wrote:<br></div><div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Mike,<div><br></div><div>You can return lists just like any other variable in Python. When you iterate over it, just remember that the returned value was a list, and not a single value. You don't need to make it into a tuple or wrap it in another list like in your example. Here's a demo for you:</div>
<div><br></div><div>def foo():</div><div> return ["baz", "bar", "quux"]</div><div><br></div><div>my_list = foo()</div><div>for x in my_list:</div><div> print x # Prints "baz\nbar\nquuz"</div>
<div><br></div><div>If you do like in your example, and put my_list = [foo()] you'll have a list of lists containing your desired list. Probably not what you're looking for.</div><div><br></div><div>Hope that helps,<br clear="all">
<div>Nick</div><br>
<br><br><div class="gmail_quote"><div><div>On Tue, Dec 27, 2011 at 7:18 PM, Mike Bean <span dir="ltr"><<a href="mailto:beandaemon@gmail.com" target="_blank">beandaemon@gmail.com</a>></span> wrote:<br></div>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
OK, I'm pretty sure this is a fairly novice question, but I'm working a project on my own and my attempts to suss the solution have met with limited success.<br>I'm writing mostly similar code over and over again, bad me. But I have to be able to return a list/array, and I don't know if return statement can handle more then just a single variable. So for example, I realize your generic scenario is <br>
<br>def function()<br> variable="whatever"<br> return(variable)<br><br>newvar=function()<br>print("newvar")<br><br>but I want to know is what's wrong with my logic in this sense:<br><br>def function()<br>
my_array=[1,2,3]<br> return(my_array)<br><br>new_array=[(my_array)]<br>for x in new_array:<br> print(x)<br><br>testing has met with no success obviously. I'm assuming it's because an array is not the same thing as a generic variable. In any case, any suggestions/guidance from folks with experience in programming/python is appreciated.<br>
<font color="#888888">
<br>Bean<br>
</font><br></div></div>_______________________________________________<br>
clue mailing list: <a href="mailto:clue@cluedenver.org" target="_blank">clue@cluedenver.org</a><br>
For information, account preferences, or to unsubscribe see:<br>
<a href="http://cluedenver.org/mailman/listinfo/clue" target="_blank">http://cluedenver.org/mailman/listinfo/clue</a><br></blockquote></div><br></div>
<br>_______________________________________________<br>
clue mailing list: <a href="mailto:clue@cluedenver.org" target="_blank">clue@cluedenver.org</a><br>
For information, account preferences, or to unsubscribe see:<br>
<a href="http://cluedenver.org/mailman/listinfo/clue" target="_blank">http://cluedenver.org/mailman/listinfo/clue</a><br></blockquote></div></div></div><br>
<br>_______________________________________________<br>
clue mailing list: <a href="mailto:clue@cluedenver.org">clue@cluedenver.org</a><br>
For information, account preferences, or to unsubscribe see:<br>
<a href="http://cluedenver.org/mailman/listinfo/clue" target="_blank">http://cluedenver.org/mailman/listinfo/clue</a><br></blockquote></div><br></div>