Replies: 7 comments
-
I forgot to add I am learning python, |
Beta Was this translation helpful? Give feedback.
-
im pretty new to programming as well; but I think one-liners are more flashy than useful. in my opinion, it is much better practice to just use whatever syntax makes sense to you as a beginner; the program you're writing likely doesn't need to be the maximum efficiency to run. i dont know any beginner projects to contribute too, i am looking too ;D |
Beta Was this translation helpful? Give feedback.
-
One liners is just an art, but in most cases it's not a good practice. It's better to give named variables that reflect the intent and split one liner to several assignments. I do each assignment several times: brute-force, optimized, functional style, one-liner. |
Beta Was this translation helpful? Give feedback.
-
Thanks for answering guys, it makes much more sense now! :) |
Beta Was this translation helpful? Give feedback.
-
In some cases, improving code efficiency and conciseness is sufficient. For beginners, readability and clarity are the most important aspects. As long as the task is completed normally without any obvious errors, that's fine. |
Beta Was this translation helpful? Give feedback.
-
It also indicates programming ability/strength/Intelligence to write code in a "CLEVER" manner. |
Beta Was this translation helpful? Give feedback.
-
It really depends on a number of factors. If you are a beginner programmer and (for example) don't really know how to implement a sorting algorithm, then I would suggest avoiding "fancy" method calls to If you're unsure about how sorting works, I suggest trying this approach: def sort(vec):
for i in range(len(vec)):
for j in range(i, len(vec)):
if vec[j] < vec[i]:
vec[i], vec[j] = vec[j], vec[i]
def main():
vec = [9, 1, 5, 3, 4, 2]
sort(vec)
print(vec) If you have already implemented or written your own sorting algorithms, you may find it beneficial to just call def main():
vec = [9, 1, 5, 3, 4, 2]
vec.sort()
print(vec) And that goes for anything if your main goal is to learn something. Unless you can write a particular method or function from memory to the point where it becomes second nature to you, I wouldn't recommend simply making one function call after another to solve a problem you couldn't otherwise solve. |
Beta Was this translation helpful? Give feedback.
-
Hello I am a beginner python programmer and I was just wondering are those one-liners really the best practice? For me it makes much more sense when the code is written clearly. For example if/elif/else statements are much easier for me to understand when they're written in this particular order even if for most of you that probably doesn't make any sense.
BTW could someone recommend me some beginner projects to make, I am really stuck because I can do some simple exercises like kata 6 here on codewars but when it comes to creating some project from scratch I fell completly lost and underwhelmed.
Cheers and I hope I will recieve some answers :) <3 Love You Guys
Beta Was this translation helpful? Give feedback.
All reactions