30 Days of Code — Day 6

Tyler Carter
1 min readMar 8, 2021

--

Photo by Chris Ried on Unsplash

As a forcing function to get myself into the habit of writing these articles — I have decided to write an article for each day of the 30 Days of Code challenge from Hacker Rank.

The Task

Given a string, S , of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line.

The Code

The Result

>? 2
...: Coding is Fun
...: Cdn sFn oigi u
>? Python
...: Pto yhn

Conclusion

I converted the string into a list but I used the step argument for slicing to only put odd or even indices in the list. This way there was no extra function definitions needed and it was scalable no matter how large the input was.

This was a fun one. I know something similar could be accomplished with lambda functions but I chose to use list comprehension because it was good practice and I knew how to do it. Hopefully the challenge for tomorrow increases in difficulty!

Here is a link to the day_5 answer/challenge I wrote about previously: 30 Days of Code — Day 5.

--

--

Tyler Carter
0 Followers

I am currently an Operations Program Manager for Microsoft. I have been teaching myself Python to use for Data Analytics and Machine Learning.