<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic In Python 3, create a function that receives two strings and returns True. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/in-python-3-create-a-function-that-receives-two/m-p/1238195#M67814</link>
    <description>&lt;P&gt;Create a Python method called check &lt;A href="https://www.scaler.com/topics/anagram-program-in-python/" target="_self"&gt;anagram()&lt;/A&gt; that receives two strings and returns True if one of them is an anagram of the other. Otherwise, the function returns False.&lt;/P&gt;&lt;P&gt;If the two strings include repeated characters but none of the characters repeat at the same location, they are termed anagrams. The strings should all have the same length.&lt;/P&gt;&lt;P&gt;Wherever possible, use case-insensitive comparison.&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def check_anagram(data1,data2):
    first = data1.lower()
    second = data2.lower()

    d1 = []
    d2 = []

    for i in range(0, len(first)):
        d1.append(first[i])
    for i in range(0, len(second)):
        d2.append(second[i])

    for_check1 = sorted(d1)
    for_check2 = sorted(d2)
    if (for_check1 != for_check2):
        return False

    count = 0
    if (len(d1) == len(d2)):
        for i in d1:
            for j in d2:
                if(i == j):
                    a = d1.index(i)
                    b = d2.index(j)
                    if(a == b):
                        return False
                    else:
                        count += 1
    if(count == len(first)):
        return True
    else:
        return False

    print(check_anagram("Schoolmaster", "Theclassroom"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although this application returns relevant results for string values such as silence, listen, Moonstarrer, Astronomerapple, and mango, it does not return results for the aforementioned two strings (in code)&lt;/P&gt;&lt;P&gt;What instances am I overlooking in this code? How can this be fixed?&lt;/P&gt;</description>
    <pubDate>Tue, 06 Dec 2022 13:01:45 GMT</pubDate>
    <dc:creator>MubashshirHasan</dc:creator>
    <dc:date>2022-12-06T13:01:45Z</dc:date>
    <item>
      <title>In Python 3, create a function that receives two strings and returns True.</title>
      <link>https://community.esri.com/t5/python-questions/in-python-3-create-a-function-that-receives-two/m-p/1238195#M67814</link>
      <description>&lt;P&gt;Create a Python method called check &lt;A href="https://www.scaler.com/topics/anagram-program-in-python/" target="_self"&gt;anagram()&lt;/A&gt; that receives two strings and returns True if one of them is an anagram of the other. Otherwise, the function returns False.&lt;/P&gt;&lt;P&gt;If the two strings include repeated characters but none of the characters repeat at the same location, they are termed anagrams. The strings should all have the same length.&lt;/P&gt;&lt;P&gt;Wherever possible, use case-insensitive comparison.&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def check_anagram(data1,data2):
    first = data1.lower()
    second = data2.lower()

    d1 = []
    d2 = []

    for i in range(0, len(first)):
        d1.append(first[i])
    for i in range(0, len(second)):
        d2.append(second[i])

    for_check1 = sorted(d1)
    for_check2 = sorted(d2)
    if (for_check1 != for_check2):
        return False

    count = 0
    if (len(d1) == len(d2)):
        for i in d1:
            for j in d2:
                if(i == j):
                    a = d1.index(i)
                    b = d2.index(j)
                    if(a == b):
                        return False
                    else:
                        count += 1
    if(count == len(first)):
        return True
    else:
        return False

    print(check_anagram("Schoolmaster", "Theclassroom"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although this application returns relevant results for string values such as silence, listen, Moonstarrer, Astronomerapple, and mango, it does not return results for the aforementioned two strings (in code)&lt;/P&gt;&lt;P&gt;What instances am I overlooking in this code? How can this be fixed?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 13:01:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/in-python-3-create-a-function-that-receives-two/m-p/1238195#M67814</guid>
      <dc:creator>MubashshirHasan</dc:creator>
      <dc:date>2022-12-06T13:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: In Python 3, create a function that receives two strings and returns True.</title>
      <link>https://community.esri.com/t5/python-questions/in-python-3-create-a-function-that-receives-two/m-p/1238267#M67815</link>
      <description>&lt;P&gt;I'm not sure what you're trying to do after line 18. Can you explain that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To check if two strings are anagrams, all you need is in your lines 1 to 16.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;convert each string into a list of characters&lt;/LI&gt;&lt;LI&gt;sort those lists&lt;/LI&gt;&lt;LI&gt;if the lists are equal, the strings are anagrams.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Instead of doing the conversion to list manually, you can just call &lt;STRONG&gt;list(your_string)&lt;/STRONG&gt;. To make it even easier, you can skip that step and call &lt;STRONG&gt;sorted(your_string)&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, this is all you need to check if two strings are anagrams:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def check_anagram(string_1, string_2):
    return sorted(string_1.lower()) == sorted(string_2.lower())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;check_anagram("a", "b")
False
check_anagram("abc", "bca")
True
check_anagram("schoolmaster", "theclassroom")
True
check_anagram("Schoolmaster", "TheClassroom")
True
check_anagram("Schoolmaster", "The Classroom")
False&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To get that last example to work, you need to ignore spaces:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def check_anagram(string_1, string_2, ignore_spaces=False):
    if ignore_spaces:
        string_1 = string_1.replace(" ", "")
        string_2 = string_2.replace(" ", "")
    return sorted(string_1.lower()) == sorted(string_2.lower())&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;check_anagram("Schoolmaster", "The Classroom")
False
check_anagram("Schoolmaster", "The Classroom", True)
True&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 06 Dec 2022 15:18:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/in-python-3-create-a-function-that-receives-two/m-p/1238267#M67815</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-12-06T15:18:58Z</dc:date>
    </item>
  </channel>
</rss>

