Exercise python: how to group element in a list?
<p>I've tried to solve the following exercise, without using datetime!</p>

<p>Exercise:</p>

<blockquote>
  <p>Given a list of int, such that the First three int represent a date,
  the second three elementi represent a date etc..modify lst by grouping
  every triple in One string with the numbers separeted by "/".</p>
</blockquote>

<p>Example:</p>

<pre><code>lst = [1, 2, 2013, 23, 9, 2011, 10, 11, 2000]
groupd(lst)
lst
['1/2/2013', '23/9/2011', '10/11/2000']
</code></pre>

<p>My attempt:</p>

<pre><code>lst = [1, 2, 2013, 23, 9, 2011, 10, 11, 2000]. 
stri = str(lst).   

def groupd(lst):. 
cont = 1. 
a = (stri.replace(',', '/')).  
    for x in lst:. 
        if len[x]&gt;2:.                
            lst.insert(lst[0],a )].   
                print(a).          
print(groupd(lst)). 
</code></pre>

<p>PS: sorry for my english!! Thank you all!</p>

<p>This is more of a functional approach where the answer is passed around with the recursive function. </p>

<pre><code>lst1 = [1, 2, 2013, 23, 9, 2011, 10, 11, 2000] 
lst2 = []
lst3 = [1,2, 2015]
lst4 = [1,2]
lst5 = [1]
lst6 = [1,2,2013, 23, 9]

def groupToDate(lst, acc): 
    if len(lst) &lt; 3:
        return acc
    else:
        # take first elements in list
        day = lst[0]
        month = lst[1]
        year = lst[2]
        acc.append(str(day) + '/' + str(month) + '/' + str(year))
        return groupToDate(lst[3:len(lst)], acc)


print(groupToDate(lst1, []))
print(groupToDate(lst2, []))
print(groupToDate(lst3, []))
print(groupToDate(lst4, []))
print(groupToDate(lst5, []))
print(groupToDate(lst6, []))
</code></pre>

<p>It's also the basic approach of solving such problem if you don't want to use list comprehensions or groupby</p>

python list