Next hour, a few questions with the string operations.
So here we have a problem where you want to change keys to location, location to upper case, and a
problem where you have to do all the string modifications to create this.
Turn this into a simple, understandable sentence.
And the third one is where you need to identify the numbers from the string and then find the average
and some of those numbers ignoring all the characters.
So you can pull boards.
Do we do now and then solve the questions?
I will be explaining the solutions after a few seconds.
I hope you would have solved these questions.
So now let's have a look at the solutions for the scene.
The first question is where we need to find out the conversion of operatives to lower keys and lower
keys to a bucket.
If I would have been a new fortune to Vitan, I would have identified by searching through the entire
list of characters here, I would have gone to all these fringe characters and checked.
If these characters were screened and then converted the uppercase lowercase and then lowercase two
of the piece.
But this is a very simple question, because Python already provides a function which allows you to
convert and to swap the cases so we can directly use that function.
So I can simply say print
string.
Don't swap it.
So we have string dot swap keys and we simply run the function.
And here you can see we have converted all the uppercase to law cases and all the normal cases to other
cases, as simple as that.
Nothing complicated.
Next, we have this particular sentence here.
Now, you can see there are a lot of problems with these sentences.
First is that you can read the sentence also that police losi are typing.
She has used special characters in place of spaces, sometimes added.
She does not even care about tendance cases.
Can you please help us connect this text?
So here you can see she has used a lot of special characters at different places.
And these are special characters are used in place of space.
So we need to handle all these one by one.
So let's simply get the print of this.
And we want to obtain different words from this.
So we see text.
From the floor, thanks in text.
Now, if we do it this way, so it will try to get each character out of it, but we don't want to get
it does we want votes.
So we split it
on the special accountability we are looking for.
So we split it on hash.
Now we need to convert this into a list as well.
Let's get the result.
So here you can see that these words have been split up into different words.
Now we want to join this.
We want to join these back together so that we can go ahead with the next function.
So instead of this, let's simply say.
Space don't join and inside join.
We give.
Now we have this now similarly, we want to split on Aderet and get this together.
So we simply say
don't join.
These.
And you want to join these after splitting it.
So this was my first one.
Make sure that you have all the jackets in place.
So no, I slipped it
on Anthony
and then.
Let's again check the brackets here.
This is for Brent.
Now, the Tascam minded on this.
Now, again, I want to do it one more time.
I have done it for hash.
I have done it for this.
Now let's capitalize these.
So I will simply say,
Don.
So here is your correct sentence.
I have done this all together in one single line of code.
You can split this phone into multiple steps.
You can use different operations instead of using what what I have used as solutions can be different.
But this is just one of the solutions which you can track.
Next question is we have this particular stream.
We want to retrieve all the numbers from the string, and then we want to find the average in some of
the numbers.
Now, because I have this string, I have a function called is numeric, which allows me to find out
if a particular character in the string is a number or not.
So let's get each and every character out of there.
So let's see if we were to let's create a list.
So we say X four kicks in a little strange.
So it gives me all the characters.
Now I want to get the characters, which are only numeric so I can simply apply if condition here.
So I see if x dot is numeric.
This will check if a character is numeric and then it will return that guy like this.
Now I have all the characters presentencing.
And I can simply get these.
I'm playing these.
I'm an average of these.
So let's find these some making him simple.
Use the function some.
We're finding this one now for finding the average.
I can use the formula that is sum divided by the length of the characters or the number of occurrences.
So I can simply say length of these, which gives me how many number of characters numbers I have.
So this is what we get.
Now, if you can see, this says unsupported operand, which is an integer.
So it is still considering X2, B and string.
So I need to convert this into an integer.
So I say eight.
And will we get the answer?
So I hope you got this correct in case these were not correct for you.
You will be waiting for them in these questions.
You can keep on practicing.
And over the time, you'll have an expertise on these.