+ 3

How can i make my Pig latin better?

I always see someone got a better version of this but i really want to know how can i improve my version of Pig Latin https://code.sololearn.com/cE2NSXokX3iT/?ref=app

13th Feb 2022, 10:17 AM
aazizul zainal
aazizul zainal - avatar
4 Answers
+ 5
Style: - start your variable names with lowercase - but do not use reserved / built-in names such as list / List Code: - avoid mutating the loop variable (x) - do not change it inside the loop - learn and use list comprehensions, and map, filter functions One liner: print(' '.join(map(lambda w: w[1:]+w[0]+'ay', input().split())))
13th Feb 2022, 10:25 AM
Tibor Santa
Tibor Santa - avatar
+ 3
Using list comprehension [print("".join(i[1:]+i[0]+"ay"),end=" ") for i in input().split()]
13th Feb 2022, 2:00 PM
Simba
Simba - avatar
+ 2
# Here’s a simple one: print(*(s[1:] + s[0] + "ay" for s in input().split()))
13th Feb 2022, 3:48 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
#shortened your code, there can be more better ways. lst = input().split() sentence="" for x in lst : sentence += x[1:]+x[0]+"ay " print(sentence)
13th Feb 2022, 10:25 AM
Jayakrishna 🇼🇳