Joining objects in lists

I’ve got a list of strings and I need to join all these strings in to one. how do I do that?
this is the code if needed:

def censor_list(email_num, to_censor):
    email_num2=email_num.replace('\n',' ' ).split(' ')
    for word in to_censor:
        for piece in email_num2:  
          if word == piece:
censor_list(email_two,["she", "personality matrix", 
"sense of self", "self-preservation", "
learning algorithm", "her", "herself"])

censor dispenser

Hey @temimam!

You can use ''.join(listname) to join the list together into a string.

Here’s an example:

list1 = ["hello", "my", "name", "is", "Steven"]

print(' '.join(list1))
-> hello my name is Steven

The way this works is it takes all the elements in the list, and joins them with a space between each element.

If you put a different character, such as the letter “a”, you would get this:

list1 = ["hello", "my", "name", "is", "Steven"]

-> helloamyanameaisaSteven

If you’d like to read more into this, checkout this topic:

1 Like

thanks @stevencopeland !

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.