dimanche 29 mars 2015

Transforming a string in a list

How can I transforms strings in list return a list consisting the elements of strings and the lengths of strings? Just like add_sizes([str]) -> [(str, int)]


Here is what I did:



def add_sizes(strings):
for i in strings:
return [(i, (len(i)))]


but this only works for one string, what should I do if I have more than one string?


Aucun commentaire:

Enregistrer un commentaire