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 trial

Python Python Basics (2015) Python Data Types Deletion

Mark Libario
Mark Libario
9,003 Points

How would you correct a spelling/name using lists, index, del function?

Kenneth mentioned somewhere you can change a spelling or/name by just changing a string to a list, deleting a certain letter by using the index of the list, and replacing it, then making it as a string again.

What are the steps for me to do that?

Let's say I want to correct this to become "Mark"

name = "Mrrk"
list_name = list(name)
del list_name[1]

I'm stuck after this and I cant think of the next steps to correct the actual spelling

1 Answer

Derek Woods
Derek Woods
6,272 Points

You can use the .insert(1, 'a') method to add the letter you want and then you can use ''.join(list_name) to turn it back into a string. I just google methods to help when I'm stuck there is usually always one that solves the problem in a simple way.