Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

on Python, given a word for example "peter" and any emoji for example "💛" how can I get this result

on Python, given a word for example "peter" and any emoji for example "πŸ’›"
how can I get this result

`word = "Peter"
emoji = "πŸ’›πŸ’›"

# Print the word with doubled letters followed by the emoji
print(''.join([l * 2 for l in word]) + emoji)

# Loop through the positions of the emoji and construct two strings for each position
for i in range(1, len(word) * 2, 2):
    first = ''.join([word[j] * 2 for j in range(i//2+1)])
    second = ''.join([word[j] * 2 for j in range(i//2+1, len(word))])
    print(first + emoji + second)
    print(first + second + emoji)

# Print the emoji followed by the reversed word with doubled letters, without the last two characters
print(emoji + ''.join([l * 2 for l in word[::-1][2:]]))`

I am not having this

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As I described. I convert the string to a list so I can use insert to insert the emoji into place. You could do this with string operations if you want.

word = "Peter"
emoji = "πŸ’›"

# Print with doubled letters.
def double(s):
    o = [l*2 for l in s]
    return ' '.join(o)

for i in range(len(word),-1,-1):
    wordl = list(word)
    wordl.insert(i,emoji)
    print(double(wordl))

Output:

PP ee tt ee rr πŸ’›πŸ’›
PP ee tt ee πŸ’›πŸ’› rr
PP ee tt πŸ’›πŸ’› ee rr
PP ee πŸ’›πŸ’› tt ee rr
PP πŸ’›πŸ’› ee tt ee rr
πŸ’›πŸ’› PP ee tt ee rr
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading