About 354,000 results
Open links in new tab
  1. Python return list from function - Stack Overflow

    Mar 26, 2019 · Python return list from function. Ask Question Asked 13 years, 2 months ago. Modified 5 years, 9 months ago.

  2. Return a list from a function in Python - Stack Overflow

    Python return list from function. 1. Returning a list in a function. 0. Returning lists from function in ...

  3. python - Returning a list in a function - Stack Overflow

    Nov 23, 2012 · Finally, python has something called a list comprehension, which does the same thing as above, but in a much more concise (and faster) way. This is the preferred method: This is the preferred method: def multiplyBy3(lst): return [item * 3 …

  4. Python Function To Return List - Stack Overflow

    Jun 8, 2010 · This is my initial function which works fine but results are not coming out as a list: def myfunc (*args): for num in args: if num % 2 == 0: print (num) When you call the function for example with the following arguments: myfunc(1,2,3,4,5,6,7,8,9,10) I am getting: 2 4 6 8 10 but I need those to be in a list, what am I missing?

  5. python - How do I get ("return") a result (output) from a function?

    The natural, simple, direct, explicit way to get information back from a function is to return it. Broadly speaking, the purpose of a function is to compute a value, and return signifies "this is the value we computed; we are done here". Directly using return. The main trick here is that return returns a value, not a variable.

  6. Returning a list from a function in Python - Stack Overflow

    May 26, 2012 · I bet you're sorting or reversing the MCreatePH list or data in the __init__ method. l.sort() and l.reverse() in Python sort and reverse in place and return None. You can try sorted(l) and reversed(l) respectively if you want a new list. But we need actual code. –

  7. How to return a list in python? - Stack Overflow

    Apr 3, 2014 · Return a list from a function in Python. 1. Python Function To Return List. 0. Python: Return a list. 0 ...

  8. python - To return elements of a list from a function - Stack …

    Jul 3, 2020 · return causes the function to stop after it hits the statement. So your for loop only ever runs once. You could use yield as mentioned in the other answers, but I really don't think you need a function in this situation. Because the function is just going to return the list that it took as an argument. What you should do is something like this:

  9. How do we get a function that returns a list in Python?

    May 11, 2022 · So, if you want to get a list out of your function you need to actually return something. Here, output starts as an empty list and gets appended with values from yout original list list_of_numbers, until the sum is higher then the passed numeric value.

  10. Is it possible to return two lists from a function in python

    Oct 18, 2019 · I am new to python programming and need your help for the following: I want to return two lists from a function in python. How can i do that. And how to read them in the main program. Examples and illustrations would be very helpful. Thanks in advance.