import re regex = r"(\d+\.\d+)(?: \1)*" test_str = "46016.0000000 46016.0000000 46016.0000000 46016.0000000 46016.0000000 46019.0000000 46019.0000000 46019.0000000 46019.0000000 46019.0000000 46015.0000000 46015.0000000 46015.0000000 46015.0000000 46015.0000000 46016.0000000 46016.0000000 46016.0000000 46016.0000000 46016.0000000 46019.0000000 46019.0000000 46019.0000000 46019.0000000 46019.0000000 46015.0000000 46015.0000000 46015.0000000 46015.0000000 46015.0000000 46016.0000000 46016.0000000 46016.0000000 46016.0000000 46016.0000000" matches = re.finditer(regex, test_str, re.MULTILINE) new_list = [] for matchNum, match in enumerate(matches, start=1): new_list.append(match.group().split(" ")) print(new_list)
Standard input is empty
[['46016.0000000', '46016.0000000', '46016.0000000', '46016.0000000', '46016.0000000'], ['46019.0000000', '46019.0000000', '46019.0000000', '46019.0000000', '46019.0000000'], ['46015.0000000', '46015.0000000', '46015.0000000', '46015.0000000', '46015.0000000'], ['46016.0000000', '46016.0000000', '46016.0000000', '46016.0000000', '46016.0000000'], ['46019.0000000', '46019.0000000', '46019.0000000', '46019.0000000', '46019.0000000'], ['46015.0000000', '46015.0000000', '46015.0000000', '46015.0000000', '46015.0000000'], ['46016.0000000', '46016.0000000', '46016.0000000', '46016.0000000', '46016.0000000']]