Short Codes
with open("file.txt", "r") as file:
content = file.read()
print(content)
numbers = [1, 2, 3, 4, 5]
squared = [x**2 for x in numbers] # Short code to transform
print(squared)
O/P: [1, 4, 9, 16, 25]
word = "hello"
letter_count = {letter: word.count(letter) for letter in word}
print(letter_count)
O/P: {'h': 1, 'e': 1, 'l': 2, 'o': 1}
words=['coding' , 'is' , 'fun' ]
' '.join(words)
o/p: 'coding is fun!'
numbers=dict(first=1,second=2,third=3)
squared_numbers={key:value**2 for key,value in numbers.items()}
o/p: {first:1,second:4,third:9}