bytes.translate()

bytes.translate(table[, delete]) bytearray.translate(table[, delete])

Return a copy of the bytes or bytearray object where all bytes occurring in the optional argument delete are removed, and the remaining bytes have been mapped through the given translation table, which must be a bytes object of length 256.

You can use the bytes.maketrans() method to create a translation table.

Set the table argument to None for translations that only delete characters:

>>> b'read this short text'.translate(None, b'aeiou')
b'rd ths shrt txt'
doc_python
2016-10-07 17:28:11
Comments
Leave a Comment

Please login to continue.