1# Remove all line breaks from a long string of text
2
3mystr = 'hello world, how do i enter line breaks?'
4>>> mystr.replace(' ', '')
5'helloworld,howdoienterlinebreaks?'
6
7# You can also replace more then one thing for example:
8mystring = mystring.replace('\n', ' ').replace('\r', '')
9
1mylist = []
2# Assuming that you have loaded data into a lines variable.
3for line in lines:
4 mylist.append(line.strip().split('\t')
1example_string = "Hello there"
2
3def remove_chars(n, string):
4 list_of_chars_in_string = [char for char in string]
5
6 for num in range(n):
7 list_of_chars_in_string.pop() # Removes last n characters in string
8
9 new_string = ''.join(list_of_chars_in_string)
10 return new_string