On this quick but efficient submit, we’ll focus on a few of the prime suggestions and methods in python that may assist you to write your code quicker 🚀
Reversing a string
s = "This can be a String"
print(s[::-1])
Eradicating duplicates from an inventory
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
b = checklist(set(a))
print(b)
Merging Two or Extra Dictionaries
a = {'a': 1, 'b': 2}
b = {'c': 3, 'd': 4}
c = {**a, **b}
- This trick would possibly solely work for Python model >= 3.5
Changing an inventory of strings right into a string
a = ['a', 'b', 'c']
b = ''.be part of(a)
print(b)
Retrieving the reminiscence dimension
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(sys.getsizeof(a), "Bytes")
print(sys.getsizeof(a) / 1024, "Megabytes")
Formatting Numbers
num1 = 100_000_000_000
num2 = 100_000_000_000
num3 = num1+num2
print(f"{num3:,}")
- The output can be
200,000,000,000
Last Ideas
- This submit might get up to date every so often
- If you need to say any methods kindly point out them within the remark part under