DEV Community

Cover image for Cracking CS50P: Thinking Through "Making Faces"
Dilesh Zingare
Dilesh Zingare

Posted on

Cracking CS50P: Thinking Through "Making Faces"

Welcome back to my new series of "Cracking CS50P: A DevAdvocate's Python Guide", today we are going to dive into how I tackled the third problem in Problem Set 0: "Making Faces" (faces.py).

If you didn't read the previous article I mean Playback Speed or playback.py then trust me you are missing the important detail in the python language. And as you know I am here to guide you in how to solve the problems I am not telling the exact answers to any problem set because you have to learn it by yourself.

**_

Recap of 2nd Article playback.py........

_**In the previous article we saw how to replace any "str" to something we want it to replace in to. But only if it's a string not a number or a float or etc., Note this one out this is a thing anyone could forget about OK.....
This article is also the same as the previous one but this time we have to replace the more than one str into something so it's going to be intresting so hang on tight.
Let me tell you a secret, As the first and the second mistake I misunderstood this one too and print out the exact statement like given in the example section. (e.g."Hello šŸ™‚") It is so funny I couldn't resist after realizing that and I begin to laugh.....

_**Let's start 3rd Article faces.py........

**_
In this part we are going to see that how to instruct the system to replace more than one string to something else. Let's get started, In previous part we use .replace( ) syntax in this part we can use this syntax and other syntax too. So, for this we can use "n" number of .replace( ) syntax for "n" number of replacements like [.replace("/", "?").replace("_", "=")] in this case we are replacing( / to ? and _ to = ) and also we can use a variable to assign the values of replacements and use

for target, emoji in replacements.items():
user_text = user_text.replace(target, emoji)
Enter fullscreen mode Exit fullscreen mode

from this we can use only one function and still get the value as the previous syntax.
So, I guess that's it for today if any has any doubt feel free to ask in the comment and if not then you can see the YouTube lecture video on my channel. See you all in the next article of CS50 intro to Python.

Top comments (0)