I'm a little late with this reply, but
enumerate()
might be a good way to do it. Can't post a clickable link, but it's one of the built-in functions and returns an iterable of tuples like (index, item)
.words = "the quick brown fox jumped over the lazy dog".split() def isFirstIndex(index, lst): return index == 0 def isLastIndex(index, lst): return index == len(lst) - 1 for i, word in enumerate(words): if isFirstIndex(i, words): print(word.upper(), end=' ') elif isLastIndex(i, words): print(word[::-1] + '.') else: print(word, end=' ')
Output:THE quick brown fox jumped over the lazy god.