Codeforces и Polygon могут быть недоступны в период с 6 декабря, 22:00 (МСК) по 7 декабря, 00:00 (МСК) в связи с проведением технических работ. ×

Блог пользователя Ibo_kudratov

Автор Ibo_kudratov, история, 29 часов назад, По-английски

When comparing programming languages, especially for competitive programming (CP), there's a clear winner: C++. Its efficiency, control over memory, and extensive STL (Standard Template Library) make it the go-to choice for top-rated users. Algorithms run faster, and intricate operations can be executed with minimal overhead. That’s why most competitive programmers swear by it.

However, no matter how good C++ is for CP, there are moments when it feels cumbersome, and I just want to switch to Python for its simplicity and elegance. For example, list comprehensions in Python are an absolute delight. With just a single line of code, you can perform complex operations on lists—something that would require several lines of loops and conditions in C++. It’s not just about saving keystrokes; it’s the readability and expressiveness that Python offers, making coding feel less like a chore and more like a creative process.

As an example, I’ve attached two photos of the quicksort algorithm implemented in both languages: Python and C++. The difference is striking.

cod

code

And I genuinely tried to write the C++ code in the simplest way possible, but even then, it remains much more verbose compared to Python.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
29 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Indeed, coding in Python is easier to read and simpler than coding in C++.

»
29 часов назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

those codes are not equal, python one uses $$$O(n\log n)$$$ memory on average, and $$$O(n^2)$$$ at worst. c++ code is always $$$O(n)$$$ memory.

and with c++20 ranges you can achieve same code length as in python, if used correctly.

»
28 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Python is in general very readable. Only the basic knowledge of English is enough to understand it.

Just like in the photo, anyone who doesn't know python will understand the code.