How do I convert Python to C++?
How do I convert C++ to Python?
Can I convert Python back to C++?
The data structures class at my school was taught in C++, but now I would like to transition to Python. I have already done so many Leetcode questions in C++ as thats the language Im the most comfortable with. Are there any resources or tips that can help with a fast and smooth transition? Thanks. FYI I have basic python experience.
Are there any libraries that can easily convert Python to C/C#/or C++? Ones where a person doesn't have to "calibrate" it, just, pip install library and then they can have their Python code in C,C#,or C++?
If the C variant needs x hours less, then I'd invest that time in letting the algorithms run longer/again
"invest" isn't the right word here.
Build a working implementation in Python. You'll finish this long before you'd finish a C version.
Measure performance with the Python profiler. Fix any problems you find. Change data structures and algorithms as necessary to really do this properly. You'll finish this long before you finish the first version in C.
If it's still too slow, manually translate the well-designed and carefully constructed Python into C.
Because of the way hindsight works, doing the second version from existing Python (with existing unit tests, and with existing profiling data) will still be faster than trying to do the C code from scratch.
This quote is important.
Thompson's Rule for First-Time Telescope Makers
It is faster to make a four-inch mirror and then a six-inch mirror than to make a six-inch mirror.Bill McKeenan
Wang Institute
Yes. Look at Cython. It does just that: Converts Python to C for speedups.
I wouldn't recommend writing it in Python and then converting to C++. Not only is it double the effort, but the style of Python code is different from C++ code, mainly because Python is dynamically typed and C++ is statically typed.
I don't have a solution for you but I can only reinforce what others have posted: don't! Even if such a solution exists, the code would very likely be quite bad and inefficient (i.e. because the c++ would have to emulate the dynamic nature of python). Whoever required you to submit c++ code probably had a reason and he will either realize you "cheated" or think you're a very bad programmer. Is this acceptable?