{"id":127383,"date":"2022-08-19T16:21:16","date_gmt":"2022-08-19T16:21:16","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=580690"},"modified":"2022-08-19T16:21:16","modified_gmt":"2022-08-19T16:21:16","slug":"how-to-ignore-case-in-strings","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/08\/19\/how-to-ignore-case-in-strings\/","title":{"rendered":"How to Ignore Case in Strings"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload=\"{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;580690&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}\">\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/div>\n<h2 class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">Problem Formulation and Solution Overview<\/h2>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">In this article, you&#8217;ll learn how to ignore (upper\/lower\/title) case characters when dealing with Strings in Python.<\/p>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\"><em>The main reason for ignoring the case of a String is to perform accurate String comparisons or to return accurate search results.<\/em><\/p>\n<p><em>For example, the following three (3) Strings are not identical. If compared with each other, they would return False.<\/em><\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>when life gives you lemons, make lemonade. <br \/>WHEN LIFE GIVES YOU LEMONS, MAKE LEMONADE.<br \/>When Life Gives You Lemons, Make Lemonade.<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p><em>This is because each character in the <a rel=\"noreferrer noopener\" href=\"https:\/\/theasciicode.com.ar\/\" data-type=\"URL\" data-id=\"https:\/\/theasciicode.com.ar\/\" target=\"_blank\">ASCII Table<\/a> assigns different numeric values for each key or key combination on the keyboard.<\/em><\/p>\n<p><em>This article outlines various ways to ignore the case of Strings.<\/em><\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity wp-embed-aspect-16-9 wp-has-aspect-ratio\" \/>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio has-global-color-8-background-color has-background\"><em><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4ac.png\" alt=\"\ud83d\udcac\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Question<\/strong>: How would we write code to compare Strings?<\/em><\/p>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">We can accomplish this task by one of the following options:<\/p>\n<ul type=\"video\" class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<li><strong>Method 1<\/strong>: Use a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\"><code>lower()<\/code><\/a> and a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" target=\"_blank\"><code>lambda<\/code><\/a><\/li>\n<li><strong>Method 2<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-upper\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-upper\/\" target=\"_blank\"><code>upper()<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/list-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/list-comprehension\/\" target=\"_blank\"><code>List Comprehension<\/code><\/a> <\/li>\n<li><strong>Method 3<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-title\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-title\/\" target=\"_blank\"><code>title()<\/code><\/a><\/li>\n<li><strong>Method 4<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html\" target=\"_blank\"><code>casefold()<\/code><\/a><\/li>\n<li><strong>Method 5<\/strong>: Use <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\"><code>lower()<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" target=\"_blank\">Dictionary Comprehension<\/a><\/li>\n<li><strong>Bonus<\/strong>: Convert CSV of Full Names to title case<\/li>\n<\/ul>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2>Method 1: Use lower() and a lambda<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This method uses <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\"><code>lower()<\/code><\/a> and a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" target=\"_blank\"><code>lambda<\/code><\/a> to convert a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\"><code>List<\/code><\/a> of Strings to lower case to search for an Employee.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">staff = ['Andy', 'MAci', 'SteVe', 'DarCY', 'Harvey']\nstaff_lower = list((map(lambda x: x.lower(), staff)))\nprint(staff_lower)<\/pre>\n<p>Above declares a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\"><code>List<\/code><\/a> of Rivers Clothing Employees. If we were searching for an Employee, such as <code>Darcy<\/code>, using this <a href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\" rel=\"noreferrer noopener\">List<\/a>, no results would return as <code>Darcy <\/code>and <code>DarCY<\/code> are not the same. Let&#8217;s fix this issue.<\/p>\n<p class=\"has-base-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/2139.png\" alt=\"\u2139\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Info<\/strong>: A <a href=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\"><code>l<\/code><\/a><code><a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" target=\"_blank\">a<\/a><\/code><a href=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\"><code>mbda<\/code><\/a> function is a <a href=\"https:\/\/blog.finxter.com\/python-one-line-x\/\" data-type=\"post\" data-id=\"10612\" target=\"_blank\" rel=\"noreferrer noopener\">one-liner<\/a> that, in this case, converts each <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\">List<\/a> element in <code>staff<\/code> to lower case. Then, converts to a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-map\/\" target=\"_blank\"><code>map()<\/code><\/a> object and back to a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\"><\/a><a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\">List<\/a>. The output saves to <code>staff_lower<\/code> and is output to the terminal.<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>['andy', 'maci', 'steve', 'darcy', 'harvey']<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>If a comparison was made now, it would find the correct Employee.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if ('Darcy'.lower() == staff_lower[3]): print('Match Found!')<\/pre>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td> Match Found!<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube\"><a href=\"https:\/\/blog.finxter.com\/how-to-ignore-case-in-strings\/\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/plugins\/wp-youtube-lyte\/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FkBg4n52XoUQ%2Fhqdefault.jpg\" alt=\"YouTube Video\"><\/a><figcaption><\/figcaption><\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2>Method 2: Use upper() and List Comprehension<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This method uses <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-upper\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-upper\/\" target=\"_blank\"><code>upper()<\/code><\/a> and a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/list-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/list-comprehension\/\" target=\"_blank\">list comprehension<\/a> to convert a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\">List<\/a> of Strings to upper case and search for an Employee.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">brands = ['ChaNnel', 'CLINique', 'DIOR', 'Lancome', 'MurAD']\nbrands_upper = [x.upper() for x in brands]\nprint(brands_upper)<\/pre>\n<p>Above declares a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\">List<\/a> of the Top five (5) Beauty Brands in the world. If we were searching for a Company, such as <code>Channel<\/code>, using this <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-lists\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-lists\/\" target=\"_blank\">List<\/a>, no results would return as <code><code>Channel<\/code><\/code> and <code>ChaNnel<\/code> are not the same. Let&#8217;s fix this issue.<\/p>\n<p>A<a href=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\"> <\/a><a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/list-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/list-comprehension\/\" target=\"_blank\">List Comprehension<\/a> is called and converts each element in <code>brands<\/code> to upper case. The results are saved to <code>brands_upper<\/code> and output to the terminal.<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code> ['CHANEL', 'CLINIQUE', 'DIOR', 'LANCOME', 'MURAD']<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>If a comparison was made now, it would find the correct Brand.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">my_fav = 'Murad'\nif (my_fav.upper() == brands_upper[4]): print(f'{my_fav} Found!')<\/pre>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td>Murad Found!<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube\"><a href=\"https:\/\/blog.finxter.com\/how-to-ignore-case-in-strings\/\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/plugins\/wp-youtube-lyte\/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FaBC0VhpXkOQ%2Fhqdefault.jpg\" alt=\"YouTube Video\"><\/a><figcaption><\/figcaption><\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2>Method 3: Use title()<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This method uses <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-title\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-title\/\" target=\"_blank\"><code>title()<\/code><\/a> to convert each word in a String to upper case. Great use of this is to convert a Full Name to title case. This ensures both the First, Middle and Last Names are as expected.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">full_name = 'jessica a. barker'.title()\nprint(full_name)<\/pre>\n<p>Above accepts a string, appends the <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-title\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-title\/\" target=\"_blank\"><code>title()<\/code><\/a> method to the string, saves it to <code>full_name<\/code> and outputs to the terminal.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Jessica A. Barker<\/pre>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube\"><a href=\"https:\/\/blog.finxter.com\/how-to-ignore-case-in-strings\/\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/plugins\/wp-youtube-lyte\/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-UkcLQxzPA4%2Fhqdefault.jpg\" alt=\"YouTube Video\"><\/a><figcaption><\/figcaption><\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2>Method 4: Use casefold() and a Dictionary<\/h2>\n<p class=\"has-global-color-8-background-color has-background\"> This method uses <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html\" target=\"_blank\"><code>casefold()<\/code><\/a> to convert a String to lower case. This method does more than <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\"><code>lower()<\/code><\/a>: it uses <a rel=\"noreferrer noopener\" href=\"https:\/\/www.unicode.org\/versions\/Unicode14.0.0\/ch03.pdf#G53253\" data-type=\"URL\" data-id=\"https:\/\/www.unicode.org\/versions\/Unicode14.0.0\/ch03.pdf#G53253\" target=\"_blank\">Unicode Case Folding Rules<\/a>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">phrase = 'Nichts ist unm\u00f6glich f\u00fcr den Unwilligen!'\ncfold = phrase.casefold()\nprint(cfold)<\/pre>\n<p>Above creates a quote in German and saves it to <code>phrase<\/code>. This ensures all characters are correctly converted to lower case, thus making a caseless match.<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code>nichts ist unm\u00f6glich f\u00fcr den unwilligen!<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>What does this say?<\/p>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2>Method 5: Use lower() and Dictionary Comprehension<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">This method uses Use <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-lower\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-lower\/\" target=\"_blank\"><code>lower()<\/code><\/a> to convert <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary\/\" target=\"_blank\">Dictionary<\/a> values into lower case using <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" target=\"_blank\">Dictionary Comprehension<\/a>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"2\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">employees = {'Sandy': 'Coder', 'Kevin': 'Network Specialist', 'Amy': 'Designer'}\nresult = {k: v.lower() for k, v in employees.items()}\nprint(result)<\/pre>\n<p>Above creates a <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary\/\" target=\"_blank\">Dictionary<\/a> containing Rivers Employees Names and associated Job Title. This saves to <code>employees<\/code>.<\/p>\n<p>Next, <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary-comprehension\/\" target=\"_blank\">Dictionary Comprehension<\/a> is used to loop through the values in the <em>key:value<\/em> <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-dictionary\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-dictionary\/\" target=\"_blank\">Dictionary<\/a> pairs and convert the values to lower case. The output saves to <code>result<\/code> and is output to the terminal.<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><code> {'Sandy': 'coder', 'Kevin': 'network specialist', 'Amy': 'designer'}<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube\"><a href=\"https:\/\/blog.finxter.com\/how-to-ignore-case-in-strings\/\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/plugins\/wp-youtube-lyte\/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FTlEC5Jx72Uc%2Fhqdefault.jpg\" alt=\"YouTube Video\"><\/a><figcaption><\/figcaption><\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2>Bonus: CSV Column to title() case<\/h2>\n<p class=\"has-global-color-8-background-color has-background\">In this Bonus section, a <a href=\"https:\/\/blog.finxter.com\/read-a-csv-file-to-a-pandas-dataframe\/\" data-type=\"post\" data-id=\"440655\" target=\"_blank\" rel=\"noreferrer noopener\">CSV file<\/a> you are working with contains a column of Full Names. You want to ensure all data entered in this column is in <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-title\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-title\/\" target=\"_blank\"><code>title()<\/code><\/a> case. This can be accomplished by running the following code.<\/p>\n<p>Contents of <code>finxter_users.csv<\/code> file<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td>FID<\/td>\n<td> Full_Name<\/td>\n<\/tr>\n<tr>\n<td>30022145<\/td>\n<td>sally jenkins<\/td>\n<\/tr>\n<tr>\n<td>30022192<\/td>\n<td>joyce hamilton<\/td>\n<\/tr>\n<tr>\n<td>30022331<\/td>\n<td>allan thompson<\/td>\n<\/tr>\n<tr>\n<td>30022345<\/td>\n<td>harry stiller<\/td>\n<\/tr>\n<tr>\n<td>30022157<\/td>\n<td>ben hawkins<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"3\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd users = pd.read_csv('finxter_users.csv')\nusers['Full_Name'] = users['Full_Name'].str.title()\nprint(users)<\/pre>\n<p>Above imports the <a href=\"https:\/\/blog.finxter.com\/category\/pandas-library\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/category\/pandas-library\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pandas<\/a> library. For installation instructions, click <a href=\"https:\/\/blog.finxter.com\/how-to-install-pandas-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/how-to-install-pandas-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n<p>Next, the <code>finxter_users.csv<\/code> file (contents shown above) is read and saved to the DataFrame <code>users<\/code>.<\/p>\n<p>The highlighted line directly accesses all values in the <code>users['Full_Name']<\/code> column and converts each entry to <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-string-title\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-string-title\/\" target=\"_blank\"><code>title()<\/code><\/a> case. This saves back to <code>users['Full_Name']<\/code> and is output to the terminal.<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><\/td>\n<td>FID<\/td>\n<td> Full_Name<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>30022145<\/td>\n<td>Sally Jenkins<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>30022192<\/td>\n<td>Joyce Hamilton<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>30022331<\/td>\n<td>Allan Thompson<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>30022345<\/td>\n<td>Harry Stiller<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>30022157<\/td>\n<td>Ben Hawkins<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/><strong>Note<\/strong>: Don&#8217;t forget to save the DataFrame to keep the changes.<\/p>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube\"><a href=\"https:\/\/blog.finxter.com\/how-to-ignore-case-in-strings\/\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/plugins\/wp-youtube-lyte\/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-JKVy_HliQE%2Fhqdefault.jpg\" alt=\"YouTube Video\"><\/a><figcaption><\/figcaption><\/figure>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h2 class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\" id=\"block-323ff1c3-82fc-4193-9c8d-125f5d3c2efb\">Summary<\/h2>\n<p class=\"wp-embed-aspect-16-9 wp-has-aspect-ratio\" id=\"block-ebf714b3-b2f5-494e-bcd5-0cd3b3709ed7\">These six (6) methods of ignoring cases in Strings should give you enough information to select the best one for your coding requirements.<\/p>\n<h2>Programmer Humor<\/h2>\n<p class=\"has-global-color-8-background-color has-background\"><em><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/2753.png\" alt=\"\u2753\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Question<\/strong>: Why do programmers always mix up Halloween and Christmas?<br \/><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/2757.png\" alt=\"\u2757\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Answer<\/strong>: Because Oct 31 equals Dec 25.<\/em><\/p>\n<p><em>(If you didn&#8217;t get this, read our articles on the <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-oct-function\/\" data-type=\"post\" data-id=\"24365\" target=\"_blank\"><code>oct()<\/code><\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-int-function\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-int-function\/\" target=\"_blank\"><code>int()<\/code><\/a> Python built-in functions!)<\/em><\/p>\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) Problem Formulation and Solution Overview In this article, you&#8217;ll learn how to ignore (upper\/lower\/title) case characters when dealing with Strings in Python. The main reason for ignoring the case of a String is to perform accurate String comparisons or to return accurate search results. For example, the following three (3) Strings [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-127383","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/127383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=127383"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/127383\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=127383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=127383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=127383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}