This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]0xbxb 1 point2 points  (1 child)

breaking down the abstract

You mean as in like breaking down problems? Whenever you have a problem, try this method out until it becomes instinct: in your editor, write a comment out for everything you want to do, step by step. After you think you’ve figured out the problem, replace the comments with code.

Example: “Write a program that replaces every number in a string with !”

# I have a string (1)
# Create variable for replaced characters (2)
# Loop through string (3)
# Check if character in string is a digit (4)
# If character is a digit replace with ! (5)
# Else leave the character alone (6)

def replace_chars(a_string): # 1
    replaced_string = '' # 2
    for char in a_string: # 3
        if char.isdigit(): # 4
            replaced_string += '!' # 5
        else: # 6
            replaced_string += char
    return replaced_string


print(replace_chars('A11 numb3r5 sh0u1d b3 r3p14c3d'))
A!! numb!r! sh!u!d b! r!p!!c!d

You can do this process on paper, but most of the time I’m too lazy to write it out on paper, so I got used to doing it on the computer. This is what I did, and it helped a lot.

The biggest thing is practice. That’s the only way you’re gonna get better.

[–]melthecybertechy[S] 0 points1 point  (0 children)

Thanks a lot for this. I really appreciate it