Python: split list of strings to a list of lists of strings by length with a nested comprehensions -


i've got list of strings , i'm trying make list of lists of strings string length.

i.e.

['a', 'b', 'ab', 'abc']  

becomes

[['a', 'b'], ['ab'], ['abc']] 

i've accomplished so:

lst = ['a', 'b', 'ab', 'abc'] lsts = [] num in set(len(i) in lst):     lsts.append([w w in lst if len(w) == num]) 

i'm fine code, i'm trying wrap head around comprehensions. want use nested comprehensions same thing, can't figure out how.

>>> [[w w in l if len(w) == num] num in set(len(i) in l)] [['a', 'b'], ['ab'], ['abc']] 

also, itertools little more efficient.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -