Jan-28-2021, 04:31 PM
(This post was last modified: Jan-28-2021, 04:42 PM by InputOutput007.)
Hi,
I want to understand the following piece of code.
I hope you can help me with it.
I mean, I read about
So, here we have 2 strings, but with different length - how does it work? I can't see it.
We obtain mapping each char to
I would be grateful if anyone would spend their time and explain it to me.
I want to understand the following piece of code.
I hope you can help me with it.
import string as str
punc = str.punctuation
string = 'ramdomforthismoment'
table_trans = string.maketrans('', '', str.punctuation)
print(table_trans)My question is - what the line where the variable table_trans is defined does?I mean, I read about
.maketrans() and it can take 1, 2 or 3 arguments. When 1, it has to be a dictionary 1-1:key-value, for 2 arguments - two strings with equal length, for 3 - strings with different length.So, here we have 2 strings, but with different length - how does it work? I can't see it.
We obtain mapping each char to
None.for k, v in table_trans.items():
print(k, v)But, I don't get it - I don't understand how it is done, this mechanism of mapping a char into the None value.I would be grateful if anyone would spend their time and explain it to me.
