entangled string manipulations in python

Recently I’ve been busy coding and studying python scripting. This is for the reason that I have nothing to do and to make my brain work while i’m on a vacation mode.

Sometimes coding makes me feel that I don’t have a real problem to deal with. This then makes me feel emotionally freeze from all the things that my heart can’t bear. The feeling of satisfaction when your scripts runs the way you wan’t it to be… totally awesome. The skills that were honed during the phase of coding is not only our mental skills but our perseverance and patience in digging the codes that aren’t supposed to be there. One good logic that we must keep our code simple and efficient aka readable for other programmer.

Sometimes when I try randomly solving exercises in python, I would have the chance to think and focus myself on solving the exercise by thinking logically on how to deal with them. Fortunately, I never quit in solving exercises because I saw how my significant half works with his programs, and I consider him as my idol in programming. I’ll do some blog about him too, if and only if he permits me.

So I setup and installed python25 on my machine.On the first day of my crashed course in python I studied the strings. You might think, why did I skipped the introduction part, it’s because I already had an idea of how python works and I’m super hyped up to do programming exercise,so I started that way. After reading the necessary stuff in strings implementation in python, I went to solve the exercises.

The first exercise is entitled both_ends: so here’s what it supposed to do,you have to get the first two strings and last two strings of a word given by a user and after that you must display the string that were removed and the strings that were combined together. Eventually I got it right, Here’s my screenshot:

The logic is that, you need to check first string length, the strings to be removed ,the combined word. I used also slice concept.

The next exercise that is about mix_up: With this one, you need to have a two words with user input and your going to swap the first word last string with second word last string and display the original words and words formed after swapping the last string of each words.

Here’s the screenshot:

The solution here is the same from the above but the swapping makes the difference, I place the last string of the first word in another variable and same with the second word’s last string, and took the length of the two strings and did a swap using slicing.

The next exercise that I had is entitle verb_ends:Given a string if it’s length is at least 3,add ‘ing’ to its end. Unless it already ends in ‘ing’, in which case add ‘ly’ instead.If the string length is less than 3, leave it unchanged. Return the resulting string.

So here’s the screenshot:

The solution here is to check first for the length of the word and then used the endswith built in to check if it ends with ing and changes the string to ly, if it word is not yet in ing form, change the word by adding ing and that is bounded by the condition that it has more that 2 letters else it must be printed same.

So this was my little homework for the past few days . I hope you enjoyed reading it although its a bit geeky.

But above all I thank the Lord above by providing me wisdom in doing this python scripting.

To you God be the Glory!


4 thoughts on “entangled string manipulations in python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s