<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aravind R</title>
    <description>The latest articles on DEV Community by Aravind R (@aravindr7991).</description>
    <link>https://dev.to/aravindr7991</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1403056%2F14a595be-805e-4293-99bf-3aaad0525669.png</url>
      <title>DEV Community: Aravind R</title>
      <link>https://dev.to/aravindr7991</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aravindr7991"/>
    <language>en</language>
    <item>
      <title>TIL#1 - translate() &amp; str.maketrans()</title>
      <dc:creator>Aravind R</dc:creator>
      <pubDate>Tue, 02 Apr 2024 16:21:53 +0000</pubDate>
      <link>https://dev.to/aravindr7991/til1-translate-strmaketrans-5fle</link>
      <guid>https://dev.to/aravindr7991/til1-translate-strmaketrans-5fle</guid>
      <description>&lt;h2&gt;
  
  
  translate()
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;translate()&lt;/strong&gt; is a string method used to obtain a new string where specified characters are replaced by others based on a mapping table or dictionary.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For mapping, the dictionary can be user defined or a mapping table can be made using &lt;strong&gt;str.maketrans()&lt;/strong&gt; method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;While defining a dictionary to use for mapping, the keys and values should be ascii values of the characters to be replaced.&lt;br&gt;
Eg: To replace "a" with "z" the dictionary should be {97:122}&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To remove a character, assign its value as **None **in the dictionary.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Syntax:
    -stringName-.translate(-dictionary-)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  str.maketrans()
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;str.maketrans()&lt;/strong&gt; creates a mapping table that can be used in translate(). It takes 2 strings as arguments. string 1 contains the characters to be replaced and string 2 contains the characters that replace them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The position of characters in both strings should be in the order of replacement. 1st character of string 1 will be replaced by 1st character in string 2 and so on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The mapping table is composed of ascii numbers of individual characters as key-value pairs. It cannot map whole words for replacement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A 3rd string can be given as an optional argument. Characters in this string will be mapped to &lt;strong&gt;None&lt;/strong&gt;, and will be removed from the returned string.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Syntax:
    str.maketrans(-string1-, -string2-, -stringOptional-)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's about it. Any additions or corrections would be appreciated.&lt;br&gt;
Happy Learning :-)&lt;/p&gt;

</description>
      <category>python</category>
      <category>todayilearned</category>
    </item>
  </channel>
</rss>
