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 trialIdan shami
13,251 Pointslittle 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
47,913 PointsYou're doing great! What happens if you iterate over the input instead of your dictionary, though?
Afloarei Andrei
5,163 PointsIf you didn't figure it out, try this:
- Before "for key, value in strange_ch.items():" write: "for letters in strange_input:"
- Change "if key in strange_input:" to "if key in letters:"
Idan shami
13,251 PointsThanks ! although I wanted to figure it out myself... but it makes more sense now !
Idan shami
13,251 PointsIdan shami
13,251 PointsThanks !