String manipulation in python

Summary of basic string operations in python

I often forget it, so make a note

Determining if a string is included

"ho" in "hoge" # True

Change and delete substrings

"hogehoge".replace('h', 'k') # "kogekoge"
"hogehoge".replace('h', '') # "ogeoge"

Convert an array to a string (of course, the contents can be converted to a string)

"".join([str(x) for x in l]) # "String"
"\t".join([str(x) for x in l]) # "tsv"

Occurrence frequency count of a specific character string

"hogehoge".count('h') # 2

Word count * However, morphological analysis has been completed and it is separated by spaces.

from collections import Counter
Counter("hoge nga kuke".split()) # {"hoge":1, "nga":1, "kuke":1}

Mutual conversion of characters to ascii code

ord('a') # 97
chr(97) # a

Extract Japanese with regular expressions (Hiragana)

import re
jap = re.compile("[Ah-Hmm]")
print(jap.findall("Hogehoge nga ward hair")) # ['Ho','Ge','Ho','Ge']

I will do my best in Unicode for kanji and symbols Unicode:Wikipedia => http://ja.wikipedia.org/wiki/Unicode

Recommended Posts

String manipulation in python
String date manipulation in Python
Date manipulation in Python
Python string manipulation master
String object methods in Python
Python string
Pixel manipulation of images in Python
File / folder path manipulation in Python
6 ways to string objects in Python
Create a random string in Python
Quadtree in Python --2
Python in optimization
CURL in python
Python: String concatenation
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
Python string format
SendKeys in Python
Python Grammar-String Manipulation
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Python2 string type
Python string format
Constant in python
Python # string type
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
Python string inversion
Python list manipulation
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python