Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def even_spacing(lst):
- new_lst = [] # list for the final output
- index_colon = [] # list of the indexs where ':' is found, for each line
- # find where the ':' in each line
- for line_string in lst:
- index_colon.append(line_string.find(':'))
- highest_index = max(index_colon) # the highest index ':' can be found at in any of the lines
- # we add the extra spaces
- for index, s in enumerate(lst):
- difference = highest_index - index_colon[index] # how many spaces will be needed
- # METHOD 1 not working, less code
- # new_lst.append(''.join(list(s).insert(index_colon[index]+1, ' '*difference))) # insert at the index we found the proper number of spaces
- # METHOD 2, working, but more code
- list_letters = list(s)
- list_letters.insert(index_colon[index]+1, ' '*difference)
- new_lst.append(''.join(list_letters))
- return new_lst
- test = ['last name: Callum', 'first name: Brian', 'middle name: Mosbey', 'balance: $0']
- print even_spacing(test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement