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>You can group the list by it's index using <code>groupby</code> from <code>itertools</code>:</p>

<pre><code>from itertools import groupby
['/'.join(str(i[1]) for i in g) for _, g in groupby(enumerate(lst), key = lambda x: x[0]/3)]

# ['1/2/2013', '23/9/2011', '10/11/2000']
</code></pre>

python list