+ 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
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())))
+ 3
Using list comprehension
[print("".join(i[1:]+i[0]+"ay"),end=" ") for i in input().split()]
+ 2
# Hereâs a simple one:
print(*(s[1:] + s[0] + "ay" for s in input().split()))
+ 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)