Hi! Welcome to my first kata.

In this kata the task is to take a list of integers (positive and negative) and split them according to a simple rule; those ints greater than or equal to the key, and those ints less than the key (the itself key will always be positive).

However, in this kata the goal is to sort the numbers IN PLACE, so DON'T go messing around with the order in with the numbers appear.

You are to return a nested list. If the list is empty, simply return an empty list.

Confused? Okay, let me walk you through an example...

    The input is: [1, 1, 1, 0, 0, 6, 10, 5, 10], the key is: 6
Okay so the first five numbers are less than the key, 6, so we group them together.

    [1, 1, 1, 0, 0]
The next two numbers, 6 & 10, are both >= 6 to they belong in a seperate group, which we will add to the first group. Like so:

    [[1, 1, 1, 0, 0], [6, 10]]
The next two numbers are 5 & 10. Since the key is 6 these two numbers form seperate groups, which we will add to the previous result. like so:

    [[1, 1, 1, 0, 0], [6, 10], [5], [10]]
And voila! We're done.
 
Here are a few more basic examples:

    group_ints([1, 0], key= 0)  
    --> [[1,0]]
  
    group_ints([1, 0, -1, 5], key= 0) 
    --> [[1, 0], [-1], [5]]
  
    group_ints([1, 0, -1, 5], key= 5) 
    --> [[1, 0, -1], [5]]

Good luck guys/gals!

Difficulty: introductory

Starter code:

def group_ints(lst, key=0):
	

Solutions:
from itertools import groupby


def group_ints(lst, key=0):
    return [list(g) for _, g in groupby(lst, lambda a: a < key)]


# PEP8: function name should use snake_case
groupInts = group_ints

from itertools import groupby

def group_ints(lst, key=0):
    return [list(g) for _, g in groupby(lst, key.__gt__)]

def group_ints(lst, key=0):
    from itertools import groupby
    return [list(group) for _, group in groupby(lst, lambda v: v >= key)]


from itertools import groupby
from operator import itemgetter

def group_ints(lst, key=0):
    # I'm keeping the cat!
    #
    #               _ |\_
    #               \` ..\
    #          __,.-" =__Y=
    #        ."        )
    #  _    /   ,    \/\_
    # ((____|    )_-\ \_-`
    # `-----'`-----` `--`
    
    return list(map(list, map(itemgetter(1), groupby(lst, key.__gt__))))

def group_ints(lst, key=0):
    first = []
    second = []
    final = []
    for i in lst:
        if i < key:
            if second:
                final.append(second)
                second = []
            first.append(i)
        else:
            if first:
                final.append(first)
                first = []
            second.append(i)
    if first:
        final.append(first)
    if second:
        final.append(second)
    return final


def group_ints(lst, key=0):
    if not lst: return []
    l, index = [[lst[0]]], 0
    for x in lst[1:]:
        if l[index][-1] < key and x < key:
            l[index].append(x)
        elif l[index][-1] >= key and x >= key:
            l[index].append(x)
        else:
            l.append([x])
            index += 1
    return l

class Nest():
    
    def __init__(self, key, list):
        self.key  = key
        self.list = list
        self.chen = 0
        self.temp_list = []
        self.new_list  = []
        
        self.ACT  = { 
                      1:self.__ap_end__, 
                      0:self.__swich__ 
                      }
                      
        self.OPER = { 
                      0:lambda a, b: a < b ,
                      1:lambda a, b : a >= b 
                      }
                      
    def __ap_end__(self, c_list, element ): 
        c_list.append(element)
        
    def __swich__(self, c_list, element):
        if c_list: 
            self.__ap_end__(self.new_list, c_list)
        self.temp_list = [element]
        self.chen = not self.chen
        
    def do_sort(self ):
        if not self.list: return []
        for e in self.list: 
            self.ACT[ self.OPER[self.chen]( e,self.key ) ]( self.temp_list, e )
        return self.new_list + [self.temp_list]

group_ints = lambda lst, key=0 : Nest( key, lst ).do_sort() 

def group_ints(lst, key=0):
    if not lst: return lst
    oper, temp, last, chen = ['<','>='], [], [], 0
    for e in lst:
        if eval(f'{e}{oper[chen]}{key}'):
            temp.append(e)
        else:
            if temp:  last.append(temp)
            temp, chen = [e], not chen
    return last + [temp]


from itertools import groupby

def group_ints(lst, key=0):
    return [list(grp) for k, grp in groupby(lst, key=lambda x: x < key)]

from itertools import groupby

def group_ints(lst, key=0):
    return [list(g) for _, g in groupby(lst, lambda x: x < key)]