Python is one such programming language that makes everything simpler and clearer. Anyone who dabbles in Python for the sake of competitive coding becomes addicted to its many features. Here is a list of some interesting features that I found most useful in a competitive programming environment.
[(1, 5), (3, 4), (4, 3)]
The output tuple clearly states that 1 has occurred 5 times, 3 happened 4 times and 4 happened 3 times.
[110, 95, 90] [20, 25, 33, 38]
The first line displays the 3 largest numbers in the list of grades ... Likewise, the second line of output outputs 4 of the smallest items present in the list evaluations. Another feature of this function is that it does not skip repetitions. So instead of n, if we put in the length of the array, we would get the entire sorted array !!
# Python code to demonstrate zip usage.
(stocks.values (), stocks.keys ())
# sort by value
zip cod e>
(stocks.keys (), stocks.values ())
# sort by key
[(39.28, 'yhoo'), (76.45,' FB'), (99.76, 'APPL'), (306.21,' AMZN'), (520.54, 'Goog')] [(' AMZN ', 306.21), (' APPL', 99.76), ('FB', 76.45), (' Goog', 520.54), ('yhoo', 39.28)]
| tr> |
[20, 60, 150]
Here we just implemented a simple function that multiplies each value in a list by two and returns it as a new list.
These functions may seem innocent individually, but will definitely come in handy in the ENVIRONMENT TIME CODING in the sense that they offer a lot of functionality in a VERY short amount of code. The functionality discussed has very specific applications and acts like SHORTCUT or CHEAT-SHEET in concurrent encoding. Having these useful tricks up your sleeve might just give someone the COMPETITIVE EDGE they were looking for!
This article is courtesy of Siddhant Bajaj . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you'd like to share more information on the topic discussed above.