Please help. There is a list of lines. You need to go through the list and if there is a line that starts with 'ORC', form a list with this line and other subsequent lines until the moment when the line that starts with 'ORC' is encountered. And then it itself. Incoming list:
lst = ['MSH|^~\\&|CENTRUM|', 'ORC|RE|100003883', 'OBR|1|100003883', 'OBX|1|NM|', 'OBX|1|NM|', 'ORC|RE|100003883-11469', 'OBR|2|100003883', 'OBX|1|NM|', 'OBX|1|NM|', 'OBX|1|NM|', 'ORC|RE|100003883', 'OBR|3|100003883', 'OBX|1|', 'ORC|RE|100003883', 'OBR|4|100003883', 'OBX|1|NM|277933'] What should be the output:
result = [['ORC|RE|100003883', 'OBR|1|100003883', 'OBX|1|NM|', 'OBX|1|NM|'], ['ORC|RE|100003883-11469', 'OBR|2|100003883', 'OBX|1|NM|', 'OBX|1|NM|', 'OBX|1|NM|'], ['ORC|RE|100003883', 'OBR|3|100003883', 'OBX|1|'], ['ORC|RE|100003883', 'OBR|4|100003883', 'OBX|1|NM|277933']] I guess that you need to move in the direction of itertools.groupby but there are not enough brains. Thank.