Python 获取两个话题的交集

CODE:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2014-06-28
@author: guaguastd
@name: intersection_between_trends.py
'''

if __name__ == '__main__':

    # import login, see http://blog.csdn.net/guaguastd/article/details/31706155 
    from login import twitter_login

    # get the twitter access api
    twitter_api = twitter_login()

    # import trend
    from trend import trend_place
    
    # computing the intersection of two sets of trends
    while 1:
        woeid1 = int(raw_input("\nInput one wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): "))
        if woeid1 == 0:
            break
        
        woeid2 = int(raw_input("\nInput another wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): "))
        if woeid2 == 0:
            break
    
        trends1 = trend_place(twitter_api, woeid1)
        trends2 = trend_place(twitter_api, woeid2)
        trends_set1 = set([trend['name'] for trend in trends1[0]['trends']])
        trends_set2 = set([trend['name'] for trend in trends2[0]['trends']])
        common_trend = trends_set1.intersection(trends_set2)
        print common_trend

RESULT:

Input one wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 1

Input another wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 23424977
set([u'#NEDvsCRC', u'Happy 5th of July', u'#CostaRicavsHolanda', u'Tim Howard in Spanish', u'#GrantLandisDMMe'])

Input one wowid (1 means WORLD_WOE_ID, 23424977 means US_WOE_ID, 0 to quit): 0<u>
</u>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值