TGViewer
Learn Python Coding Learn Python Coding @pythonre Β· 40.7K subscribers
Post #9705 1.91K
πŸ“Œ How to make code cleaner with any() and all() 🐍

Do you often have to check lists for compliance with conditions? Forget about cumbersome loops! πŸš«πŸ”„

any() β€” returns True if at least one element is true. βœ…
all() β€” returns True only if all elements are true. πŸ”’

# Example: checking if there are negative numbers
numbers = [1, 5, -3, 7]

# Bad: through a loop
has_negative = False
for num in numbers:
if num < 0:
has_negative = True

# Beautiful:
has_negative = any(num < 0 for num in numbers) # True ✨
Telegram AI PYTHON 🌟 You’ve been invited to add the folder β€œAI PYTHON πŸŒŸβ€, which includes 15 chats.
  • ❀ 3
More from @pythonre
  1. Oct 7, 2026A distinctive bot for subscribing to courses on the most popular educational platforms acr…
  2. Oct 7, 2026Python Lists: A Quick Reference 🐍 * Definition: Lists are ordered, mutable collections th…
  3. Oct 7, 2026πŸ“± 270 tools for Python developers The repository contains: 🫑 Linters and formatters; πŸ«‘β€¦
  4. Oct 7, 2026Hands On Python Data Science - Data Science Bootcamp Master Python for Data Science with R…
  5. Oct 6, 2026Post #9851
  6. Oct 6, 2026Python For Beginners Course In-Depth Python: A Comprehensive Introduction to Fundamental P…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook β†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 β†’