반응형
출처 : http://cdpython.tistory.com/16
파이썬에서 url 인코딩 / 디코딩
1 2 3 4 5 6 7 | from urllib import quote,unquote#인코딩def urlencode(string): print "URLEncoding:",quote(string)#디코딩def urldecode(string): print "URLDecoding:",unquote(string) |
해시(md5,sha1) 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 | import hashlibdef hash_string(string): print "MD5:",hashlib.md5(string).hexdigest() print "SHA1:",hashlib.sha1(string).hexdigest()#파일 해시 생성def hash_file(file_path): try: f = open(file_path,'rb').read() except Exception as e: print "Faild to open file [%s]" % file_path return print "MD5:",hashlib.md5(f).hexdigest() print "SHA1:",hashlib.sha1(f).hexdigest() |
입력 가능한 모든 문자열에서 빈도수 top 5 출력
1 2 3 4 5 6 7 8 9 10 11 12 13 | from string import lowercase,uppercasefrom operator import itemgetterdef letter_count(string): result=[] print_able=lowercase+uppercase+"0123456789!@#$%^&*()_+-=[]{}:;''/?.>,<`~" for i,j in enumerate(print_able): result.append([i,string.count(j)]) #print j,string.count(j) print "\n[+]Top 5!!\n" #itemgetter 해당 item의 2번째 값으로 정렬 후 내림차순으로 result=sorted(result, key=itemgetter(1), reverse=True) for i in range(5): print "Top"+`i+1`,print_able[result[i][0]],result[i][1] |
반응형
'old > Python' 카테고리의 다른 글
| [자료] 파이썬을 활용한 업무 자동화 (0) | 2018.08.22 |
|---|---|
| [Tool] 파이썬 기반 도구 모음 (0) | 2017.05.22 |
| [Tool] Py2Exe Decompiler (0) | 2017.04.27 |
| [정리] ocr 라이브러리 pytesser import 및 예제 (0) | 2017.03.13 |
| [자료] 파이썬 공부자료 모음 (0) | 2014.06.07 |