TGViewer
پایتون | Data Science | Machine Learning پایتون | Data Science | Machine Learning @python4all_pro · 24.3K subscribers
Post #2392 3.6K
Top 10 Python One Liners!

1️⃣ Reverse a string:
reversed_string = "Hello World"[::-1]


2️⃣ Check if a number is even:
is_even = lambda x: x % 2 == 0


3️⃣ Find the factorial of a number:
factorial = lambda x: 1 if x == 0 else x * factorial(x - 1)


4️⃣ Read a file and print its contents:
[print(line.strip()) for line in open('file.txt')]


5️⃣ Create a list of squares:
squares = [x**2 for x in range(10)]


6️⃣ Flatten a list of lists:
flat_list = [item for sublist in [[1, 2], [3, 4], [5, 6]] for item in sublist]


7️⃣ Find the length of a list:
length = len([1, 2, 3, 4])


8️⃣ Create a dictionary from two lists:
keys = ['a', 'b', 'c']; values = [1, 2, 3]; dictionary = dict(zip(keys, values))


9️⃣ Generate a list of random numbers:
import random; random_numbers = [random.randint(0, 100) for _ in range(10)]


🔟 Check if a string is a palindrome:
is_palindrome = lambda s: s == s[::-1]



📱 @Python4all_pro
  • ❤ 3
More from @python4all_pro
  1. Sep 26, 2026🔻 به علت محدود بودن ظرفیت کانال ها، لیست به زودی پاک خواهد شد. https://t.me/addlist/bdUfn…
  2. Sep 26, 2026🚀دیگه هزینه نجومی برای اشتراکای هوش مصنوعی نکن!! @GptPLuserBot ➖➖➖➖➖➖➖ 🔺آموزش برنامه نوی…
  3. Sep 26, 2026📖 Turn a PDF into an Animated Flipbook with Python! Want to make your PDFs more interacti…
  4. Sep 26, 2026🤖 مینی دوره Claude رایگان شد! | ابزار برنامه‌نویسی، تحقیق و حل مسئله ✔️ توی این مینی‌دوره…
  5. Sep 23, 2026📚 کتاب‌ «۳۰۰ برنامه پایتون» منبع فوق‌العاده برای یادگیری پایتون از صفر تا سطح مصاحبه‌های…
  6. Sep 22, 2026با رعایت کردن این نکات اسکریپت‌های پایتون سریعتر عمل می‌کنند @python4all_pro
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 →