[Tutor] using a for loop in another method

Rene.Castillo jackalren at gmail.com
Fri Apr 22 12:08:25 EDT 2016


Hi, this is my first post on this mailing list-

I wanted to ask about this type of execution in python,

expected output-
reverse_words("This is an example!") # returns  "sihT si na !elpmaxe"


below is my execution, followed by another persons execution, which i dont
completely understand.

def reverse_words(strng):
  strng = strng[::-1].split(' ')
  strng.reverse()
  return ' '.join(strng)


def reverse_words(s)
    return ' '.join(s[::-1] for s in str.split(' '))



how can a for loop be called within another method like that- and possibly
what situations does this benefit
i don't even know how to google this sort of thing
any words are appreciated-



R


More information about the Tutor mailing list