FAQ
I'm making this exercise: (Python 3.3)


Write a function translate() that will translate a text into "r?varspr?ket" (Swedish for "robber's language"). That is, double every consonant and place an occurrence of "o" in between. For example, translate("this is fun") should return the string "tothohisos isos fofunon".


So I tried to solved it, but I couldn't, so I found many answers, but I selected this:


def translate(s):
   consonants = 'bcdfghjklmnpqrstvwxz'
   return ''.join(l + 'o' + l if l in consonants else l for l in s)


print(translate('hello code solver'))




OUTPUT:
'hohelollolo cocodode sosololvoveror'


______________________________________________________________
So I want to question:
How is the


if 'h' in consonants else 'h' for 'h' in s


part evaluated? (step by step please :P )


''.join('h' + 'o' + 'h' if 'h' in consonants else 'h' for 'h' in s)


Thank you guys

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 7 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedJul 4, '13 at 5:20p
activeJul 5, '13 at 8:38a
posts7
users6
websitepython.org

People

Translate

site design / logo © 2022 Grokbase