TGViewer
Python Learning Python Learning @python_bds · 5.75K subscribers
Post #856 1.4K
Top Python tricks for efficient programming

Strings

Trick 6: Reversing the string

a=”python”
print(“Reverse is”, a[::-1])

Output:
Reverse is nohtyp

Trick 7: Splitting the string

a="Python is the language of the future"
b=a.split()
print(b)

Output:
[‘Python’, ‘is’, ‘the’, ‘language’, ‘of’, 'the’, ‘future’]

Trick 8: Printing out multiple values of strings

print(“on”*3+’ ‘+”off”*2)

Output:
ononon offoff

Trick 9: Creating a single string

a = [“I”, “am”, “not”, “available”]
print(“ “.join(a))

Output:
I am not available

Trick 10: Checking if two words are anagrams

from collections import Counter
def is_anagram(str1, str2):
return Counter(str1) == Counter(str2)
print(is_anagram(‘taste’, ‘state))
print(is_anagram(‘beach’, ‘peach’))

Output:
True
False
  • 👍 4
  • ❤ 2
More from @python_bds
  1. Oct 12, 2026📌 The most comprehensive Python cheat sheet! And it's free on GitHub Basic datatypes, Gen…
  2. Oct 11, 2026📘 The Big Book of Small Python Projects ✍️ Author: Al Sweigart 🔗 Read Online #Python #Pr…
  3. Oct 10, 2026document post
  4. Oct 10, 2026This Book Explains more than 400 Concepts with codes.
  5. Oct 8, 2026🐛 This Python Bug Looks Random, But It Isn't Look at this: functions = [] for i in range(…
  6. Oct 6, 2026🐍 Python Performance Optimization Python Performance Optimization: Make Your Code Faster…
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 →