DEV Community

Cover image for Python challenge_22πŸβš”οΈ
Mahmoud EL-kariouny
Mahmoud EL-kariouny

Posted on β€’ Edited on

3

Python challenge_22πŸβš”οΈ

Duplicate Encoder

  • The goal of this exercise is to convert a string to a
    new string where each character in the new string is "("
    if that character appears only once in the original string,
    or ")" if that character appears more than once in the original
    string.

  • Ignore capitalization when determining if a character is a duplicate.

Examples:

    "din"      =>  "((("
    "recede"   =>  "()()()"
    "Success"  =>  ")())())"
    "(( @"     =>  "))(("
Enter fullscreen mode Exit fullscreen mode
Task URL: Link

My Solution:

def duplicate_encode(word):

    return "".join(["(" if word.lower().count(x) == 1 else ")"
                    for x in word.lower()])


print(duplicate_encode("recede"))

Enter fullscreen mode Exit fullscreen mode

Connect with Me 😊

πŸ”— Links

linkedin

twitter

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay