list in def function
Question:
I have been trying to solve this problem in def function for doing a list and return it but it seems have to use your help.
def something():
a_list = []
a_list.append("note")
return a_list
def main():
b_list = []
c = something()
b_list.append(c)
print(b_list)
main()
Output:
['note'] #normally will print note only
Answers:
You need to use .extend
instead of .append
Can you try the following:
def something():
a_list = []
a_list.append("note")
return a_list
def main():
b_list = []
c = something()
b_list.extend(c)
print(b_list)
main()
Output:
['note']
Try using .extend
instead of .append
:
b_list.extend(c)
I have been trying to solve this problem in def function for doing a list and return it but it seems have to use your help.
def something():
a_list = []
a_list.append("note")
return a_list
def main():
b_list = []
c = something()
b_list.append(c)
print(b_list)
main()
Output:
['note'] #normally will print note only
You need to use .extend
instead of .append
Can you try the following:
def something():
a_list = []
a_list.append("note")
return a_list
def main():
b_list = []
c = something()
b_list.extend(c)
print(b_list)
main()
Output:
['note']
Try using .extend
instead of .append
:
b_list.extend(c)