In Competitive Programming, it is important to read input as fast as possible to save valuable time. Input/Output in Python can be sometimes time taking in cases when the input is huge or to output any numbers of lines or a huge number of arrays(lists) line after line.
Normally, the input is taken from STDIN in the form of String using input(). And this STDIN is provided in the Judge’s file. So try reading the input directly from the Judge’s file using the Operating system(os) module, and input/output (io) module. This reading can be done in the form of bytes. By using this method, integer input works normally, but for string input, it will store the string as a byte like an object. For correcting this, the string can be decoded using the decode function.
Below is the implementation for Fast I/O in Python:
Instead of outputting to the STDOUT, we can try writing to the Judge’s system file. The code for that would be to use sys.stdout.write() instead of print() in Python. But remember we can only output strings using this, so convert the output to a string using str() or map().
Below is the implementation for the Fast Output:
- Fast I/O for Competitive Programming
- Fast I/O in Java in Competitive Programming
- Tips and Tricks for Competitive Programmers | Set 2 (Language to be used for Competitive Programming)
- Input/Output from external file in C/C++, Java and Python for Competitive Programming
- Python Input Methods for Competitive Programming
- Input/Output from external file in C/C++, Java and Python for Competitive Programming | Set 2
- Python in Competitive Programming
- Which Python Modules are useful for competitive programming?
- Mathematics Tricks For Competitive Programming In Python 3
- How to Setup VSCode with C, C++ and Python for Competitive Programming
- Top 10 Algorithms and Data Structures for Competitive Programming
- How to begin with Competitive Programming?
- How to become a master in competitive programming?
- Competitive Programming: Conquering a given problem
- A Better Way To Approach Competitive Programming
- getchar_unlocked() - faster input in C/C++ for Competitive Programming
- Bitwise Hacks for Competitive Programming
- Some important shortcuts in Competitive Programming
- Frequency Measuring Techniques for Competitive Programming
- Graph implementation using STL for competitive programming | Set 1 (DFS of Unweighted and Undirected)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.