Advertisement
Davitkova

emoji_with_defs

Jul 30th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. def calculate_cool_threshold(input_string):
  5.  
  6.     threshold = 1
  7.  
  8.     for char in input_string:
  9.        
  10.         if char.isdigit():
  11.             threshold *= int(char)
  12.  
  13.     return threshold
  14.  
  15.  
  16. def get_valid_emojis(emojis_input):
  17.  
  18.     valid_emojis = list()
  19.     emoji_pattern = r"(\*\*|\:\:)([A-Z][a-z]{2,})\1"
  20.  
  21.     matched_emojis = re.finditer(emoji_pattern, emojis_input)
  22.  
  23.     for match in matched_emojis:
  24.         valid_emojis.append(match.group())
  25.  
  26.     return valid_emojis
  27.  
  28.  
  29. def cool_emoji(emoji_string, threshold):
  30.  
  31.     emoji_coolness = 0
  32.  
  33.     for char in emoji_string:
  34.  
  35.         if char.isalpha():
  36.             emoji_coolness += ord(char)
  37.  
  38.     if emoji_coolness >= threshold:
  39.         return True
  40.  
  41.     return False
  42.  
  43.  
  44. emojis_string = input()
  45. cool_threshold_sum = calculate_cool_threshold(emojis_string)
  46. emojis = get_valid_emojis(emojis_string)
  47.  
  48. print(f"Cool threshold: {cool_threshold_sum}")
  49. print(f"{len(emojis)} emojis found in the text. The cool ones are:")
  50.  
  51. for emoji in emojis:
  52.     if cool_emoji(emoji, cool_threshold_sum):
  53.         print(emoji)
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement