Advertisement
Guest User

02. Emoji Detector

a guest
Jul 26th, 2023
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. text = input()
  2. cool_threshold = 0
  3. cool_emoji = []
  4. regex = r"([:]{2}|[\*]{2})([A-Z][a-z]{2,})\1"
  5.  
  6. digits = re.findall(r"\d", text)
  7. for digit in digits:
  8.     if cool_threshold == 0:
  9.         cool_threshold = int(digit)
  10.     else:
  11.         cool_threshold *= int(digit)
  12. matches = re.findall(regex, text)
  13. for match in matches:
  14.     ascii_letters_values = 0
  15.     for letter in match[-1]:
  16.         ascii_letters_values += ord(letter)
  17.  
  18.     if ascii_letters_values > cool_threshold:
  19.         cool_emoji.append(f"{match[0]}{match[-1]}{match[0]}")
  20.  
  21.  
  22. print(f"Cool threshold: {cool_threshold}")
  23. print(f"{len(matches)} emojis found in the text. The cool ones are:")
  24. print(*cool_emoji, sep='\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement