9 things every beginner programmer should stop doing:
β Copy-pasting code without understanding it
β© Skipping the fundamentals to learn advanced stuff
π Rewriting the same code instead of reusing functions
π¦ Ignoring file/folder structure in projects
β οΈ Not handling errors or exceptions
π§ Memorizing syntax instead of learning logic
β³ Waiting for the βperfect ideaβ to start coding
π Jumping between tutorials without building anything
π€ Giving up too early when things get hard
#coding #tips
β Copy-pasting code without understanding it
β© Skipping the fundamentals to learn advanced stuff
π Rewriting the same code instead of reusing functions
π¦ Ignoring file/folder structure in projects
β οΈ Not handling errors or exceptions
π§ Memorizing syntax instead of learning logic
β³ Waiting for the βperfect ideaβ to start coding
π Jumping between tutorials without building anything
π€ Giving up too early when things get hard
#coding #tips
π2
If you work with Python, remember a simple rule: do not modify a list while iterating over it. ππ This can lead to unexpected results because the iterator does not track structural changes.
Here is an example that looks logical but works incorrectly: π€
It seems that all 2s should disappear, but one remains. β Why?
After removing an element, the list shifts, but the loop moves on β as a result, some values are simply skipped. ππ«
How to do it correctly β iterate over a copy: β
Even better β use list comprehension: π
items = [x for x in items if x != 2]
Conclusion: π do not modify a collection during iteration. This can lead to skipped elements, duplication, or even errors during execution. π οΈπ§
#Python #Coding #Programming #Debugging #TechTips #PythonTips
Here is an example that looks logical but works incorrectly: π€
items = [1, 2, 2, 3, 4]
for item in items:
if item == 2:
items.remove(item)
print(items)
# Output: [1, 2, 3, 4]
It seems that all 2s should disappear, but one remains. β Why?
After removing an element, the list shifts, but the loop moves on β as a result, some values are simply skipped. ππ«
How to do it correctly β iterate over a copy: β
for item in items[:]:
if item == 2:
items.remove(item)
print(items)
# Output: [1, 3, 4]
Even better β use list comprehension: π
items = [x for x in items if x != 2]
Conclusion: π do not modify a collection during iteration. This can lead to skipped elements, duplication, or even errors during execution. π οΈπ§
#Python #Coding #Programming #Debugging #TechTips #PythonTips
π2