+ 1

Is Sololearn teaching any ways to optimize the code?

https://www.sololearn.com/en/compiler-playground/cbTmuu6hj7S7 Maybe later in the course or in a separate course? For the record, i'm pushing through the old Python Core. To me, this code somehow feels a little crude (i am a beginner, after all). Anything that can be done to streamline it? Also, the approach i used in the code can be used to pull specific elements out of one list and place them in 2, 3, n other lists, according to a specific criteria in the if statement(s), right? That is, if i'm thinking in the right direction.

22nd Jan 2025, 6:50 AM
Igor Matić
Igor Matić - avatar
1 Respuesta
+ 6
Hi Igor Matić, Great that you’re thinking about improving your code! Here are some key tips: • Follow PEP 8 for readability. • Use functions to keep code modular. • List comprehensions and generators can simplify loops. • Efficient algorithms and data structures boost performance. • Caching helps avoid redundant calculations. • Read and revisit code – Studying others’ code and refining your own is key to improving over time. And yes, your approach of distributing elements based on conditions is a useful technique.
22nd Jan 2025, 8:07 AM
Per Bratthammar
Per Bratthammar - avatar