Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def replaceWithQuestionMarks(lines):
- # (assumes each line in lines is the same length)
- newLine = [] # this will contain the characters/question marks
- # loop over each index in a line:
- for i in range(len(lines[0])):
- charactersInAllLines = []
- # loop over each line, populating charactersInAllLines with the ith character in the line
- for line in lines:
- charactersInAllLines.append(line[i])
- # convert to a set to get rid of duplicate characters, check if there's only 1 unique character
- if len(set(charactersInAllLines)) == 1:
- newLine.append(charactersInAllLines[0]) # add the character to the new line
- else:
- newLine.append('?') # append a question mark
- return ''.join(newLine) # convert the list of strings into a single string
- print(replaceWithQuestionMarks(['121212123434AA6AAA', '121212222234AAAAAB', 'D21212122434AAAAAF']))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement