<jupyter_start><jupyter_text>18 bad habits in Python programming, you must abandon themRef: How to improve your Python programming levelThese bad habits will expose the developer’s inexperience in Python. By abandoning these habits and writing code in a Pythonic way, you can improve the quality and reputation of your code.  1. Use + sign for splicing strings<jupyter_code># Bad practice:
name = "Anderson"
subscribers = 1_000_000

print("Wow " + name + "! you have " + str(subscribers) + " subscribers!")

print("Lol " + name + " that's not many subs")
# A good practice is to use f-string, and it will be more efficient:
name = "Anderson"
subscribers = 1_000_000

print(f"Wow {name}! you have {subscribers} subscribers!")
print(f"Lol {name} that's not many subs")<jupyter_output>Wow Anderson! you have 1000000 subscribers!
Lol Anderson that's not many subs<jupyter_text>11. Use a C-style for loop<jupyter_code># Bad practice
a = [1, 2, 3]
b = [4, 5, 6]

for i in range(len(a)):
    print(a[i])

for i in range(len(b)):
    av = a[i]
    bv = b[i]
    print(av, bv)
# Good practice
a = [1, 2, 3]
b = [4, 5, 6]

for v in a:
    print(v)

# or if you wanted the index
for i, v in enumerate(a):
    print("enumerate: ", i, v)

# instead use zip
for av, bv in zip(a, b):
    print(av, bv)<jupyter_output>1
2
3
enumerate:  0 1
enumerate:  1 2
enumerate:  2 3
1 4
2 5
3 6
{'fraction_non_alphanumeric': 0.11338697878566203, 'fraction_numerical': 0.038771031455742504, 'mean_word_length': 4.029411764705882, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '615715', 'license': 'Apache-2.0', 'n_tokens_mistral': 542, 'n_tokens_neox': 493, 'n_words': 198, 'path': 'bkp/best_practices.ipynb', 'repo_name': 'asantos2000/master-data-structures-algorithms', 'size': '1367'}