Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Feel free to explore, learn, and share your own approaches.
- [ ] **3/18:** [Flight Vouchers](https://github.com/codedex-io/daily-challenges/tree/main/march-2026/3-18-flight-vouchers) 🏖️
- [ ] **3/19:** [March Madness](https://github.com/codedex-io/daily-challenges/tree/main/march-2026/3-19-march-madness) 🏀
- [ ] **3/20:** Cherry Blossoms 🌸
- [ ] **3/21:** First Tweet 🐦
- [x] **3/21:** [First Tweet](https://github.com/codedex-io/daily-challenges/tree/main/march-2026/3-21-first-tweet) 🐦
- [ ] **3/22:** ❓❓❓
- [ ] **3/23:** ❓❓❓
- [ ] **3/24:** ❓❓❓
Expand Down
29 changes: 29 additions & 0 deletions march-2026/3-20-first-tweet/first-tweet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def tweet_balance(tweet):
# first we split the tweet and initialize the char count
split_tweet = tweet.split(" ")
char_count = 0

# for each word in the split tweet
for word in split_tweet:
# if @ add 20
if word.startswith("@"):
char_count += 20
# if url add 23
elif word.startswith("http://") or word.startswith("https://"):
char_count += 23
else:
# for each character
for char in word:
# if ascii value at least 0x1F000 it means it's an emoji
if ord(char) >= 0x1F000:
char_count += 2
else:
char_count += 1

# space after each word
char_count += 1

# no trailing space after last word
char_count -= 1

return (140 - char_count)