如何使用Python从字符串中删除重复的字符?例如,假设我有一个字符串:
foo = "SSYYNNOOPPSSIISS"
Run Code Online (Sandbox Code Playgroud)
我该如何制作字符串:
foo = SYNOPSIS
Run Code Online (Sandbox Code Playgroud)
我是python的新手,我已经厌倦了,而且它正在工作.我知道有聪明和最好的方法来做到这一点......只有经验可以证明这一点..
def RemoveDupliChar(Word):
NewWord = " "
index = 0
for char in Word:
if char != NewWord[index]:
NewWord += char
index += 1
print(NewWord.strip())
Run Code Online (Sandbox Code Playgroud)
注意:顺序很重要,这个问题是不是类似于此一个.
我已经实现了logstash(在测试中)如下面提到的架构.

组件分解
但我对redis有点困惑.使用这个场景我将在Logstash服务器和一个redis上运行3个java进程,这将需要hugh ram.
问题 我可以只使用一个logstash和弹性搜索吗?或者最好的方法是什么?
我正在尝试以下示例:
python -c "import sys; print sys.argv[1]" "test\ntest"
输出:
test\ntest
Run Code Online (Sandbox Code Playgroud)
但我想要跟随
test
test
Run Code Online (Sandbox Code Playgroud)
更新1#由于@devnull建议可以解决问题,如果用户自己通过了$但是python应该如何解决这个问题?
我试过了 :
python -c "import sys; print '$' + sys.argv[1]" 'test\ntest'
Run Code Online (Sandbox Code Playgroud)
但输出:
$test\ntest
Run Code Online (Sandbox Code Playgroud) 我的设置:
卷曲 - > AWS ELB - > Nginx - > NodeJS
当请求数量高时,我面临这个问题.
Nginx访问日志
xx.xx.xx.xx - - [30/Oct/2014:13:23:40 +0000] "POST /some/calls/object HTTP/1.1" 499 0 "-" "curl/7.27.0"
xx.xx.xx.xx - - [30/Oct/2014:13:23:40 +0000] "POST /some/calls/object HTTP/1.1" 499 0 "-" "curl/7.27.0"
Run Code Online (Sandbox Code Playgroud)
Nginx错误日志
2014/10/30 13:23:40 [info] 11181#0: *17811 client xx.xx.xx.xx closed keepalive connection
2014/10/30 13:23:40 [info] 11181#0: *17631 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream, client: xx.xx.xx.xx, server: example.com, request: "POST /some/calls/objects HTTP/1.1", …Run Code Online (Sandbox Code Playgroud) In [54]: User
Out[54]: {0: {'uid': ' rpatil\n'}, 1: {}}
In [55]: User[0]
Out[55]: {'uid': ' rpatil\n'}
In [56]: User[1]
Out[56]: {}
In [57]: if User[1] == '':
....: print 'Null'
....:
In [58]:
Run Code Online (Sandbox Code Playgroud)
那么如何在多字典中检查Value是Null
我试过以下链接但不工作 python字典中没有值
我仍然按照python gzip document设置文件时间戳,语法不像gzip.GzipFile(filename=outputfile,mode='wb',compresslevel=9,mtime=ftime),但是当我使用时gzip.GzipFile(outputfile,'wb',9,mtime=ftime),除了时间戳,它可以工作。
def compresse_file(file,ftime):
data = open(file,'rb')
outputfile = file +".gz"
gzip_file = gzip.GzipFile(outputfile,'wb',9,mtime=ftime)
gzip_file.write(data.read())
gzip_file.flush()
gzip_file.close()
data.close()
os.unlink(file)
Run Code Online (Sandbox Code Playgroud)
这是输出:
root@ubuntu:~/PythonPractice-# python compresses_file.py
Size Date File Name
5 MB 30/12/13 test.sh
Compressing...
test.sh 1388403823.0
file status after compressesion
5 kB 31/12/13 test.sh.gz
root@ubuntu:~/PythonPractice-# date -d @1388403823.0
Mon Dec 30 17:13:43 IST 2013
Run Code Online (Sandbox Code Playgroud) 示例文件名是
abc.edf.xdc
pqe.ide.xdc
rm -rf "*.\*.xdc" 不管用