我的程序是用来打印那些看到“tweets”最多的前n用户,以及他们会看到多少条tweets。seen tweet被定义为来自他们关注的用户的tweet,当他们在tweet、DM中被提到(@user),或者作为转发tweet的作者时
使用虚拟文件(following.txt):
andrew fred
fred
judy andrew fred
george judy andrew
john george
第一个单词是用户,字符串中剩余的单词是他们跟随的人
一段代码,用于确定每个用户跟随谁:
for line in lines:
names = line.split()
follow_dict[names[0]] = len(names)-1
if max_follower < len(names)-1:
max_follower = len(names)-1
使用第二个虚拟文件(stream.txt)显示常规活动:
andrew I hate mondays.
fred Python is cool.
fred Ko Ko Bop Ko Ko Bop Ko Ko Bop for ever
andrew @fred no it isn't, what do you think @john???
judy @fred enough with the k-pop
judy RT @fred Python is cool.
andrew RT @judy @fred enough with the k pop
george RT @fred Python is cool.
andrew DM @john Oops
john DM @andrew Who are you go away! Do you know him, @judy?
代码输出的示例应该是:
Enter n: 10
6 judy
5 fred george
3 andrew john
通常情况下,如果我在这里寻求帮助,我至少会有一些代码来显示它的工作原理,但不完全如预期的那样或有错误。这次我甚至不知道从哪里开始。如果有人能帮助我,我将非常感激
我认为你可以这样解决(从每个用户那里统计他们看到的tweet),但是效率太低了(twitter不能这样做)。还有一种方法:
相关问题 更多 >
编程相关推荐