Answer the question
In order to leave comments, you need to log in
How to return each list value from a function in Python and pass those values to another?
There is a structure like this:
User {
Name: Abc
}
There is a function that looks for the string "Name" in the file, which is a signal to write the substring after "Name:" into the variable strFromTextData. Let's conditionally imagine that we have extracted the name of a certain user into a variable. (the number of possible similar entries in the file is not limited)
After that, we add the name to the userNamesArray list and so on until the very end of the file.
Okay, we got an array with names.
But here's how to return it in such a way that each value can migrate from it to another list and you can work with it normally?
If you just write
"return userNamesArray"
After that, use the function to assign a return value to a variable, then Python will give a TypeError error, and I didn’t succeed in extracting the data in any way from such a list.
Here is the code https://pastebin.com/mydEF3vP
Answer the question
In order to leave comments, you need to log in
Just push the list into the list.
userArray.extend(userNamesArray)
list_ = []
def func():
return [1, 2, 3]
list_.extend(func())
# OR
list_ += func()
# OR
def func():
for el in [1, 2, 3]:
yield el
for el in func():
list_.append(el)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question