Задача с собеседования #Python

Задача с собеседования #Python

Телеграм канал Codewars

Решение №1

import string

def pig_it(text):
    splited_text = text.split()
    return " ".join([f"{item[1:] + item[0]}top" if item not in string.punctuation else item for item in splited_text])

Решение №2

def pig_it(text):
    res = []
    
    for i in text.split():
        if i.isalpha():
            res.append(i[1:]+i[0]+'ay')
        else:
            res.append(i)
        
    return ' '.join(res)

Решение №3

import re

def pig_it(text):
    return re.sub(r'([a-z])([a-z]*)', r'\2\1ay', text, flags=re.I)

Решение №4

def pig_it(text):
    lst = text.split()
    return ' '.join( [word[1:] + word[:1] + 'ay' if word.isalpha() else word for word in lst])


Report Page