Changes between Version 5 and Version 6 of WikiStart


Ignore:
Timestamp:
08/14/24 14:16:34 (9 months ago)
Author:
Enrico Schwass
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart

    v5 v6  
    4747schedule = Schedule(unrolled)
    4848}}}
     49
     50Certainly! Let's break down the task with an example:
     51
     52### Given:
     53- You have a list of lists.
     54- You want to split each sublist at the point where the sublist starts with a given symbol.
     55
     56### Example:
     57
     58#### Input:
     59```python
     60list_of_lists = [
     61    ['a', 1, 2, 3],
     62    ['b', 4, 5, 6],
     63    ['*', 7, 8, 9],
     64    ['c', 10, 11],
     65    ['*', 12, 13],
     66    ['d', 14, 15, 16]
     67]
     68symbol = '*'
     69```
     70
     71#### Expected Output:
     72```python
     73[
     74    [['a', 1, 2, 3], ['b', 4, 5, 6]],
     75    [['*', 7, 8, 9], ['c', 10, 11]],
     76    [['*', 12, 13], ['d', 14, 15, 16]]
     77]
     78```
     79
     80### Steps:
     81
     821. **Initialize an empty result list**: This will hold the final split sublists.
     832. **Iterate through each sublist**: Check if the first element of the sublist is the given symbol.
     843. **When the symbol is found**: Start a new group in the result list.
     854. **Continue grouping until the symbol is encountered again**.
     86
     87### Python Code Implementation:
     88
     89```python
     90def split_list_of_lists(list_of_lists, symbol):
     91    result = []
     92    current_group = []
     93   
     94    for sublist in list_of_lists:
     95        if sublist[0] == symbol and current_group:
     96            result.append(current_group)
     97            current_group = []
     98        current_group.append(sublist)
     99   
     100    if current_group:
     101        result.append(current_group)
     102   
     103    return result
     104
     105# Example usage
     106list_of_lists = [
     107    ['a', 1, 2, 3],
     108    ['b', 4, 5, 6],
     109    ['*', 7, 8, 9],
     110    ['c', 10, 11],
     111    ['*', 12, 13],
     112    ['d', 14, 15, 16]
     113]
     114symbol = '*'
     115output = split_list_of_lists(list_of_lists, symbol)
     116print(output)
     117```
     118
     119### Output:
     120```python
     121[
     122    [['a', 1, 2, 3], ['b', 4, 5, 6]],
     123    [['*', 7, 8, 9], ['c', 10, 11]],
     124    [['*', 12, 13], ['d', 14, 15, 16]]
     125]
     126```
     127
     128This code takes a list of lists and splits it into separate groups whenever a sublist starts with the specified symbol. Each group is then added to the result. The result is a list of these grouped sublists.