test = [['ma', 'e', 'wa', 'ka'], ['ma', 'haa', 'laa'], ['ma', 'ka', 'm',
    'haa', 'laa', 'ca', 'j', 'ra'], ['ma', 'ra'], 'ma']
test = sorted(test, key=lambda x: len(x) if type(x) == list else 1)
Sort order of lists in multidimensional array in Python