Learn various Python tips and tricks through Python Snippets.
Python Snippets 📸




Code 💻
Find the frequency of characters in a string
from collections import Counter
string = "Hello"
print(Counter(string))
Merge 2 lists into a dictionary
# Merge Two Lists into a Dictionary
keys = [1, 2, 3]
values = ['John', 'Samy', 'Adam']
dict_kv = dict(zip(keys, values))
Print Variable Names using f-string
fruit = 'Apple'
count = 11
print(f'{fruit = } & {count = }')
Extract elements from a list
nums = [1, 2, 3]
print(nums) # [1, 2, 3]
print(*nums) # 1 2 3
If you have not installed python then download it from here. For more Python related posts, click here.
Comments