Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: is_anagram.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- - This script determines whether a given string is an anagram or not.
- - An anagram is a word or phrase formed by rearranging the letters of another word or phrase.
- - This script takes a string as input and checks if it is an anagram. It ignores the case of the letters.
- Requirements:
- - Python 3.x
- - The script requires the following Python module:
- - collections module with the Counter class
- Functions:
- check_anagram(string):
- Checks if the given string is an anagram.
- Usage:
- Run the script and provide the string to check when prompted.
- Additional Notes:
- - An empty string or a string containing only whitespace will be considered as an anagram.
- """
- from collections import Counter
- def check_anagram(string):
- """
- Checks if the given string is an anagram.
- Args:
- string (str): The string to check.
- Returns:
- bool: True if the string is an anagram, False otherwise.
- """
- # Count the occurrences of each character in the string
- return Counter(string)
- if __name__ == '__main__':
- # Get the input string from the user
- input_string = input("\nEnter The String: ")
- # Check if the input string is an anagram
- if check_anagram(input_string):
- print("\nThe string is an anagram!\n")
- else:
- print("\nThe string is not an anagram!\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement