I'm new to Python and trying to figure out a rather simple way to count the output of a defined function. I want to count the number of unique users who have replied to a given username by defining a function to do this.
st='@'
en=' '
task1dict={}
for t in a,b,c,d,e,f,g,h,i,j,k,l,m,n:
if t['text'][0]=='@':
print('...'),print(t['user']),print(t['text'].split(st)[-1].split(en)[0])
user=t['user']
repliedto=t['text'].split(st)[-1].split(en)[0]
task1dict.setdefault(user, set())
task1dict[user].add(repliedto)
task1dict['realDonaldTrump'].add('joeclarkphd')
This returns what is below when I enter
print(task1dict)
{'datageek88': {'fundevil', 'joeclarknet', 'joeclarkphd'},
'fundevil': {'datageek88'},
'joeclarkphd': {'datageek88'},
'realDonaldTrump': {'datageek88', 'joeclarkphd'},
'sundevil1992': {'datageek88', 'joeclarkphd'}}
I then want to print all the Twitter users who replied to a certain user for example, all the people who replied to datageek88 is done by
def print_users_who_got_replies_from(tweeter):
for z in task1dict:
if tweeter in task1dict[z]:
print(z)
This prints me what is below when I enter:
print_users_who_got_replies_from('datageek88')
fundevil
joeclarkphd
sundevil1992
realDonaldTrump
Now, I want to count the number of replies by defining a function that then prints how many people replied to a user. This function should return the answer as a number (4), but I can't seem to get that part to work, any suggestions or help? Thanks! I have tried using the len() function but can't seem to get that to work, although it might be the answer.