M
M
michadimin2021-11-14 04:06:14
Python
michadimin, 2021-11-14 04:06:14

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

2 answer(s)
I
Ilya Boyarsky, 2021-11-14
@Bashuha

Just push the list into the list.
userArray.extend(userNamesArray)

C
Coder 1448, 2021-11-14
@wows15

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 question

Ask a Question

731 491 924 answers to any question