Dec-30-2018, 02:24 AM
Here is the Udemy instructor's challenge:
Here is my solution:
For my future reference, the course material I am working is publicly available here: Pierian-Data/Complete-Python-3-Bootcamp. The specific sub- module I am working on is: 03-Methods and Functions/03-Function Practice Exercises.ipynb
Quote:Write a function that capitalizes the first and fourth letters of a name
old_macdonald('macdonald') --> MacDonald
Here is my solution:
def old_macdonald(name): first_cap = name[0].capitalize() + name[1:3] second_cap = name[3].capitalize() + name[4:] together = first_cap + second_cap return togetherThis produces the desired output:
MacDonald
but I was wondering how you people would perhaps optimize this or re-write it in a more Pythonic way?For my future reference, the course material I am working is publicly available here: Pierian-Data/Complete-Python-3-Bootcamp. The specific sub- module I am working on is: 03-Methods and Functions/03-Function Practice Exercises.ipynb