Python Challenges: Convert string to camel case

Transcript

English (Auto-generated)

Hello everyone and welcome to another code cast in python. Um So today we're gonna be doing another simple python challenge. Um Not as simple as the other ones we've done but still like the way I'm going to solve it is very simple. So basically we're going to be given a string and we have to turn into camel case. Very simple instructions if you guys aren't familiar with what camel case looks like. I'm just gonna show you guys really quick. It's basically um this isn't a case with regard to use right now. This right here is string to Campbell. That's the weakest string. Yeah. Next. I don't know life out of that, but that's the thing. Right, okay. We use an underscore or even dash. Alright. But we're not gonna do that in camel case, there's no thing separating it. But you put when beginning a new word, you just make it happen like a string next. That's what camera face looks like. Okay, I hope I was able to explain it properly and you know um Okay. So yeah, now. Okay. Okay. The way we're going to do this is that we're going to first turn it into a list. Okay. So what we're gonna do here is okay, we're gonna do rest. Okay. Equaled list. Sure. Perfect. And the way we're gonna leave. This is using a while. We haven't done much many wild loops in a while. And what we're gonna do is index currently april's one and then we're going to have a place where we're going to have our new string and right now it's just going to equal an empty string. Okay perfect. Now we're going to do while index is less than lessen the length of string. Okay. This is how we're going to look through it and then we're gonna do the following. Okay. And please next index like the current thinking on. Yes it equals a dash or Okay. I'll explain this or in a second. Um or anyone that I just don't care or text. Index. Text index, let's say close underscore then we're gonna do the phone. Okay. Oh I keep calling it pets string. Index and strengthen. Okay. Perfect. Okay. Now what we're gonna do is we're going to write actual code. Okay. So so if it equals that were first and make it equal to nothing. Just an empty extreme. Okay. And then it's called string. It's called list string. Okay. String list Okay equals let's just string. I keep getting mixed up with the name. I'm sorry. Now it's going to equal wait for the string. Mhm Sorry. Blistering isn't gonna equal an empty string. It's got the index is going to demonstrate the current element we're on is going to equal an empty string. Okay now we're gonna do index plus one. Okay. So we get the next character and let's string index plus one is going to be uppercase dot upper like that. Thanks. So. Okay. Perfect. And we did that upper outside of the if statement we're gonna always plus people want to index. Perfect. Yeah. And now we're just going to return the string version of our list string and that's going to be a new string. Okay. Start join text less strain. Okay. There we go. Okay. And now let's try it out. Okay so let's say we okay lets try crimped outside of our function obviously um stream thank you two camel and then we're, what we're gonna do here is give it a little extreme. Let's do let's try this out. Okay. And I used a lot of underscores right there. Okay, now we're gonna open up a terminal Pikes on three and then the bar file as always. Oh also sorry, let me edit that. Rename this really quick. I never put dot pi Oh man. Okay. I would stop. Okay. Straight to get camel case that pi, let's check it out. Let's try this out. And it works to balance her with dashes. Yes and crunch. Okay, now let's say that. Mhm. And it works perfectly. Um let's try with two words just really quick just to try out different things. String camera. Okay. And oh I put a w I did not want to put that okay. And or perfectly. Okay, so as you can see this is kind of like the best way to do this if you thought of a different way to do it or a different way to reflect with them. Always let me know. I love being see other people's solutions. I find them a lot more creative than mine. But thanks for tuning in and we'll do a different private challenge another day. Goodbye.
204 Views 1 Likes 0 Comments

Simple. We're given a string and we must convert it to camel case.

Comment
Leave a comment (supports markdown format)