UPDATED: If you want your tabulated() function to call your labeled function, you have a couple of different options for structuring your code:
Option 1: The labeled() function only queries the user once, then both prints and returns the resulting lstA. The tabulated() function calls the labeled() function, gets the returned output and processes it into the desired list of lists:
def labeled():
lstA = []
result = input("Enter a message or type q to end: ")
if result == "q":
return False
for i in result.split():
if "#" in i:
lstA.append(i[1:])
print(f'labeled output: {lstA}')
return lstA
def tabulated():
dic = {}
for item in labeled():
if item not in dic:
dic[item] = 1
else:
dic[item] += 1
list_of_lists = [[a,b] for a,b in dic.items()]
print(list_of_lists)
tabulated()
#output:
Enter a message or type q to end: Nice day #running #10k #power #running
labeled output: ['running', '10k', 'power', 'running']
[['running', 2], ['10k', 1], ['power', 1]]
Option 2: The labeled() function queries the user multiple times as per your code. It not only prints lstA each time, but also appends each lstA into an aggregate list of lists. When the while loop is exited, it returns this aggregate list. When the tabulated function() calls the labeled function, it reads through the aggregate list item by item (line by line) and prints a desired list_of_list output for each line that the user had entered.
def labeled():
aggregate_list = []
while(True):
lstA = []
result = input("Enter a message or type q to end: ")
if result =='q':
break
else:
for i in result.split():
if "#" in i:
lstA.append(i[1:])
print(f'labeled output: {lstA}')
aggregate_list.append(lstA)
return aggregate_list
def tabulated():
for sentence in labeled():
dic = {}
for item in sentence:
if item not in dic:
dic[item] = 1
else:
dic[item] += 1
list_of_lists = [[a,b] for a,b in dic.items()]
print(list_of_lists)
tabulated()
#output:
Enter a message or type q to end: Nice day #running #10k #power #running
labeled output: ['running', '10k', 'power', 'running']
Enter a message or type q to end: Great to #see #you and #see #your #dad
labeled output: ['see', 'you', 'see', 'your', 'dad']
Enter a message or type q to end: q
[['running', 2], ['10k', 1], ['power', 1]]
[['see', 2], ['you', 1], ['your', 1], ['dad', 1]]