DEV Community

Henrique Lopes
Henrique Lopes

Posted on

How do I improve my python skills

I'll give you a simple tip about improving your python skills. It’s very simple and of the bonus is that many technology companies apply your challenges over there. I'm speaking about Hackerrank which is a famous platform where you can practice coding and find jobs . I usually take up one coding challenge per week, I like math problems and Python.

You can find range of problems over there, it starts from basic to the most difficult ones, at every step you get a different level problem . I use this tool to think better and to practise. My profile contact is contato44. I'll share a simple problem that you can to see on Hackerrank:

"""
    >>> count_substring("ABCDCDC", "CDC")
    2
    >>> count_substring("ABCDCDCAAAACDC", "CDC")
    3
    >>> count_substring("ThIsisCoNfUsInG", "is")
    1
"""


def count_substring(string, sub_string):
    occurrences = 0

    for i, __ in enumerate(string):
        cut = string[i:len(sub_string)+i]
        if cut == sub_string:
            occurrences += 1
    return occurrences

To solve the problem I'm using the Doctest, because is it simple and fast to write the test. I submit the solution with Doctest. You can execute the Doctest of 2 modes in your machine:

First mode:

PS: After to execute the code, add the snippet in final code.

if __name__ == "__main__":
   import doctest
   doctest.testmod()

Run the test feature.

$ python Findastring.py

Seconde mode:

ps: When I use the Doctest to run my test feature, this what I do.

$ python -m doctest Findastring.py

Today I share a simple tip on improving your developer skill, If have another tip, kindly let me know.

Originally post on:
https://medium.com/@riquellopes/how-do-i-improve-my-python-skills-89075f2e22e2

Top comments (0)