CyberChants has Published 3 Articles

What is the difference between encode/decode in Python?

CyberChants

CyberChants

Updated on 30-Sep-2019 07:32:24

2K+ Views

To represent a unicode string as a string of bytes is known as encoding. To convert a string of bytes to a unicode string is known as decoding. You typically encode a unicode string whenever you need to use it for IO, for instance transfer it over the network, or ... Read More

How to find all possible permutations of a given string in Python?

CyberChants

CyberChants

Updated on 30-Sep-2019 07:31:30

8K+ Views

To find all possible permutations of a given string, you can use the itertools module which has a useful method called permutations(iterable[, r]). This method return successive r length permutations of elements in the iterable as tuples. In order to get all the permutations as string, you'll need to iterate over ... Read More

How to convert string to binary in Python?

CyberChants

CyberChants

Updated on 30-Sep-2019 07:29:16

640 Views

To convert a string to binary, you need to iterate over each character and convert it to binary. Then join these characters together in a single string. You can use format(ord(x), 'b') to format the character x as binary. For example:>>>st = "hello world" >>>' '.join(format(ord(x), 'b') for x in ... Read More

1
Advertisements