Is there a way to filter these lines from a list of lines that contains, for example, 3 identical characters per line? I created a method that can do this, but I'm curious if there is a more pythonic way, or a more efficient or easier way to do this.
list_of_strings = [] def check_3_in_row(string): for ch in set(string): if ch*3 in string: return True return False new_list = [x for x in list_of_strings if check_3_in_row(x)]
EDIT: I just found one solution:
new_list = [x for x in set(keywords) if any(ch*3 in x for ch in x)]
But I'm not sure which way is faster - regexp or this.
source share