Advertisement
Python253

is_anagram

May 13th, 2024
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: is_anagram.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script determines whether a given string is an anagram or not.
  10.    - An anagram is a word or phrase formed by rearranging the letters of another word or phrase.
  11.    - This script takes a string as input and checks if it is an anagram. It ignores the case of the letters.
  12.  
  13. Requirements:
  14.    - Python 3.x
  15.    - The script requires the following Python module:
  16.        - collections module with the Counter class
  17.  
  18. Functions:
  19.    check_anagram(string):
  20.        Checks if the given string is an anagram.
  21.  
  22. Usage:
  23.    Run the script and provide the string to check when prompted.
  24.  
  25. Additional Notes:
  26.    - An empty string or a string containing only whitespace will be considered as an anagram.
  27. """
  28.  
  29. from collections import Counter
  30.  
  31. def check_anagram(string):
  32.     """
  33.    Checks if the given string is an anagram.
  34.  
  35.    Args:
  36.        string (str): The string to check.
  37.  
  38.    Returns:
  39.        bool: True if the string is an anagram, False otherwise.
  40.    """
  41.     # Count the occurrences of each character in the string
  42.     return Counter(string)
  43.  
  44. if __name__ == '__main__':
  45.     # Get the input string from the user
  46.     input_string = input("\nEnter The String: ")
  47.  
  48.     # Check if the input string is an anagram
  49.     if check_anagram(input_string):
  50.         print("\nThe string is an anagram!\n")
  51.     else:
  52.         print("\nThe string is not an anagram!\n")
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement