Python Tricks For Competitive Coding PDF
Python Tricks For Competitive Coding PDF
Custom Search
Courses
Write an Article
Python Tricks for Competitive Coding
Python is one such programming language which makes everything easier and straight
forward. Anyone who has dabbled in python for Competitive Coding gets somewhat
addicted to its many features. Here is list of some of its cool features that that I’ve found
most useful in a competitive coding environment.
Output:
The output tuple clearly states that 1 has occured 5 times, 3 has occured 4 times,
and 4 has occured 3 times.
https://www.geeksforgeeks.org/python-tricks-competitive-coding/ 1/6
5/9/2019 Python Tricks for Competitive Coding - GeeksforGeeks
Output:
The rst line of output gives 3 of the largest numbers present in the list grades.
Similarly the second line of output prints out 4 of the smallest elements present in
the list grades. Another speciality of this function is that it does not overlook
repetitions. So in place of n if we were to place the length of the array the we would
end up with the entire sorted array itself !!
https://www.geeksforgeeks.org/python-tricks-competitive-coding/ 2/6
5/9/2019 Python Tricks for Competitive Coding - GeeksforGeeks
# sorting according to values
print(sorted(zipped_1))
zipped_2 = zip(stocks.keys(), stocks.values())
print(sorted(zipped_2))
#sorting according to keys
Output:
Output:
Here, we just implemented a simple function which multiplies each list value by two
and returns it as a new list.
Individually these functions might look innocent but will de nitely come in handy in a
TIME LIMITED CODING ENVIRONMENT in the sense that they offer large functionality in
a VERY short amount of code. The functionalities discussed have very speci c
applications and act like a SHORTCUT or a CHEAT-SHEET in competitive coding. Having
these useful tricks up your sleeve might just give someone the COMPETITIVE EDGE that
they were looking for !!
https://www.geeksforgeeks.org/python-tricks-competitive-coding/ 3/6
5/9/2019 Python Tricks for Competitive Coding - GeeksforGeeks
This article is contributed by Siddhant Bajaj. If you like GeeksforGeeks and would like to
contribute, you can also write an article using contribute.geeksforgeeks.org or mail your
article to contribute@geeksforgeeks.org. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
Please write comments if you nd anything incorrect, or you want to share more
information about the topic discussed above.
Recommended Posts:
Tips and Tricks for Competitive Programmers | Set 2 (Language to be used for
Competitive Programming)
Why is python best suited for Competitive Coding?
Bit Tricks for Competitive Programming
C++ tricks for competitive programming (for C++ 11)
Some useful C++ tricks for beginners in Competitive Programming
Tips and Tricks for Competitive Programmers | Set 1 (For Beginners)
BFS using STL for competitive coding
Java tricks for competitive programming (for Java 8)
Selenium Python Tricks
10 Interesting Python Cool Tricks
10 Essential Python Tips And Tricks For Programmers
Python in Competitive Programming
Python Input Methods for Competitive Programming
Input/Output from external le in C/C++, Java and Python for Competitive Programming
Input/Output from external le in C/C++, Java and Python for Competitive Programming |
Set 2
7
https://www.geeksforgeeks.org/python-tricks-competitive-coding/ 4/6
5/9/2019 Python Tricks for Competitive Coding - GeeksforGeeks
Based on 3 vote(s)
Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
✉ Subscribe d Add Disqus to your siteAdd DisqusAdd 🔒 Disqus' Privacy PolicyPrivacy PolicyPrivacy
https://www.geeksforgeeks.org/python-tricks-competitive-coding/ 5/6
5/9/2019 Python Tricks for Competitive Coding - GeeksforGeeks
COMPANY LEARN
About Us Algorithms
Careers Data Structures
Privacy Policy Languages
Contact Us CS Subjects
Video Tutorials
PRACTICE CONTRIBUTE
Company-wise Write an Article
Topic-wise Write Interview Experience
Contests Internships
Subjective Questions Videos
https://www.geeksforgeeks.org/python-tricks-competitive-coding/ 6/6