我有以下形式的字符串:
"\nMy objective is to work with a progressive & innovative
organisation where I can implement my skills, knowledge and \nachieve
success.\n\nPHP\nSDE 2 \nQuikr\nZend\n(CommonFloor merged with
Quikr)\nTasks\nTo develop Quikr Jobs portal\nLaravel\nTo develop
intent-form to increase o\xef\xac\x84ine signups\nTo develop sales CRM
tool\nJava\n \nSDE 1 J2EE\nCommonFloor\nTasks\nJava Spring\nTo work on
hybrid mobile app for residential communities\nTo develop APIs for
CommonFloor Groups\nJavaScript\n\nSDE 1 \njQuery\nIDrive India Pv
Ltd.\nTasks\nAngular JS\nTo develop APIs for cloud storage\nTo add front-end functionalities for online backup and data sync\nGulp\n\nSDE 1 " …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 geograpy ( https://pypi.python.org/pypi/geograpy/0.3.7 )从文本文件中提取国家/城市名称,但它返回一个空列表。我的代码是:
import geograpy
text = 'I am from Delhi'
places = geograpy.get_place_context(text=text)
print places.cities
Run Code Online (Sandbox Code Playgroud)
输出:
[]
Run Code Online (Sandbox Code Playgroud)
为什么不提取城市名称?有什么办法可以解决吗??
如何在python中对元素元组进行排序,首先是基于值,然后是基于键.考虑我将用户输入作为字符串的程序.我想找出每个字符的数量,并在字符串中打印3个最常见的字符.
#input string
strr=list(raw_input())
count=dict()
#store the count of each character in dictionary
for i in range(len(strr)):
count[strr[i]]=count.get(strr[i],0)+1
#hence we can't perform sorting on dict so convert it into tuple
temp=list()
t=count.items()
for (k,v) in t:
temp.append((v,k))
temp.sort(reverse=True)
#print 3 most common element
for (v,k) in temp[:3]:
print k,v
Run Code Online (Sandbox Code Playgroud)
给予i/p -aabbbccde
上述代码的输出是:
3 b
2 c
2 a
Run Code Online (Sandbox Code Playgroud)
但我希望输出为:
3 b
2 a
2 c
Run Code Online (Sandbox Code Playgroud) 我希望在Twitter(https://twitter.com/HousingWire)上收到HousingWire的每条推文.我知道如何验证Twitter帐户,但我如何获得HousingWire的推文?
我知道如何根据关键字流式传输数据,但我想流式传输HousingWire推文.我怎么能这样做?
import time
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
ckey=''
csecret=''
atoken=''
asecret=''
class listener(StreamListener):
def on_data(self,data):
try:
print data
#tweet=data.split(',"text":"')[1].split('","source')[0]
#print tweet
#savethis=str(time.time())+'::'+tweet
savefile=open('tweetdb.txt','a')
savefile.write(data)
savefile.write('\n')
savefile.close()
return True
except BaseException,e:
print 'failed on data',str(e)
time.sleep(5)
def on_error(self,status):
print status
auth=OAuthHandler(ckey,csecret)
auth.set_access_token(atoken,asecret)
twitterStream=Stream(auth,listener())
twitterStream.filter(track=["stock"])
Run Code Online (Sandbox Code Playgroud)