Member-only story

10 Python Tips for Competitive Programming

With a surprise time complexity cheat sheet

Pramod Kumar
Better Programming
3 min readJun 8, 2021

--

Person surprised at phone content
Photo by Andrea Piacquadio from Pexels

Python is now the number one choice for most programmers. The main reason is — Python is easy to understand and a small learning curve. We can be good with our Python programming skills in a week time.

Although it is easy to understand, when we take part in competitive programming, we face issues with the code run time and the slowness of the Python program.

Here I am with some tricks that can help you speed up your code by using the right set of programming snippets to improve your Python code.

1. Checking Memory Usage of Any Object

While doing competitive programming, memory and time are the two main constraints. If you want to track the memory usage, you can use the following code snippet.

Code Snippet:

import sys
dic = {'a': 3, 'b': 2, 'c': 1, 'd': 1}
print(sys.getsizeof(dic))

Output:

240

2. Use of Map Function

Single line list type input is usually seen in competitive programming. Here is the single line of Python code that can help you get the list…

--

--

Responses (5)

Write a response