Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
89 views
in Technique[技术] by (71.8m points)

python - how to assign function output to variable

im trying to get the list that is outputted by the function and assign the list to a variable so i can use the len method on it but I don't know how

def count(list):
return ([i for item in list for i in item.split()])

list = [""]

question from:https://stackoverflow.com/questions/65928183/how-to-assign-function-output-to-variable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Does this answer your question?

def count(item_list):
    return ([i for item in item_list for i in item.split()])

list_returned_by_count = count(item_list)

Then, you can use the len method on it.

len(list_returned_by_count)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...