Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Idan shami
Idan shami
13,251 Points

little project

I wanted to start a little project(very little) in python, to see if I learned something. Unfortunately, I didn't succeed so much.... I wanted to convert letters into signs( | , $...), I converted the letters into signs, but my problem was that no matter what order I wrote the letters, the order didn't change..... so here is my code

def translate():
    strange_list = []
    strange_ch = {"a": "|", "b": "*", "c": "$"}
    while True:
        print(''.join(strange_list))
        strange_input = input("write your sentence: ")
        if strange_input == "QUIT":
            break
        else:
            for key, value in strange_ch.items():
                if key in strange_input:
                    strange_list.append(value)

    print(''.join(strange_list))

The order is always |*$ do I need to change the whole code, a bit, or write a bit on top of it? am I even allowed to ask it? (: also, I noticed that if I write the letters separately one after another it does show me the order I gave. but if I write all of them in one line it doesn't.

Thanks anyway.

Idan.

2 Answers

Michael Hulet
Michael Hulet
47,912 Points

You're doing great! What happens if you iterate over the input instead of your dictionary, though?

Afloarei Andrei
Afloarei Andrei
5,163 Points

If you didn't figure it out, try this:

  1. Before "for key, value in strange_ch.items():" write: "for letters in strange_input:"
  2. Change "if key in strange_input:" to "if key in letters:"
Idan shami
Idan shami
13,251 Points

Thanks ! although I wanted to figure it out myself... but it makes more sense now !