Python Challenges: Name Shuffler

Transcript

English (Auto-generated)

everyone, how is everybody doing? So um today we're gonna be doing another python challenge. This one is again a very simple challenge. So what we're gonna be doing today is a name shuffler. So basically we're going to be given a string with the first and last name, both on the same string obviously and we have to return a string with the name reversed. So we want the first the last name to come before the first. Okay, so for example, really quick right here if we're given um Maria via Maria Maria, we want to return the uh Maria just like that. So I hope that made sense. So um there's multiple ways that you can go about this, but the way I'm going to go about this is by creating a list first with the string. So I'm gonna use the split function um with split off everything. Um and how it works is that you put as stuff split like that. And let's just print it really quick fantasy, what it gives us just so you guys kind of see how it works. Name shuffler. And let's put okay let's put money up once again because I can't think of anything right now. Okay And we're gonna put Python three, the name of our file and the none their returns now. Okay, so see okay oh sorry, I didn't realize what we need to return list. We weren't returning anything going inside about that. Okay now it returns a list with Maria and via separated if that's kind of how split works right there. Okay, so now that we have it in a list like that, we're going to create a new list, let's just call it reverse splits because this is what we're going to reverse it and we're going to make a list with The original list, Index one, which is actually going to be the second element because it starts from zero And the list zero. So this is gonna be the first element and this is gonna be a second element and the second element is coming first as you can see, okay now what we're gonna do is just put that into our new strength right there with using dot join. So here you just put what you want to join it dry and we're just gonna join it by that with space dot join and then we're gonna join the red list right there and then we're just going to return our new string with the reverse splits as in the reverse name. And let's try it out. Now print um let's do print name, shuffler chocolate. And we're gonna try with first right there and let me see what happens when you return to the Amalia. Now let's try it with the different things let's try tom Cruise. This is the first thing he talked into my head and it returns Cruise tom So as you can see our code works pretty well. And um yeah, so if you guys would like you could try re factoring this yourself or seeing how you guys would do this, because there's a lot of different ways that you could go about this anyway, So thank you so much for tuning in and we'll do another python challenge later.
101 Views 0 Likes 0 Comments

We are given a string with a first and last name, our job is to return a string with the last name first and the first name last. Hope I explained that...

Comment
Leave a comment (supports markdown format)