[Tutor] Need help combining elements of a list of lists

David Rock david at graniteweb.com
Tue Jul 10 23:09:56 EDT 2018


> On Jul 10, 2018, at 22:04, David Rock <david at graniteweb.com> wrote:
> 
>> On Jul 10, 2018, at 21:46, Jim <jf_byrnes at comcast.net> wrote:
>> 
>> ltrs = [['A', 'B'], ['C', 'D', 'E'], ['F', 'G', 'H', 'I']]
> 
> A fairly straightforward way is to use nested loops:
> 
>>>> for l in ltrs[0]:
> ...   for j in ltrs[1]:
> ...     for k in ltrs[2]:
> ...       print l,j,k
> 

Sorry, let’s try to make that a little cleaner-looking

for x in ltrs[0]:
  for y in ltrs[1]:
    for z in ltrs[2]:
      print x,y,z


— 
David Rock
david at graniteweb.com






More information about the Tutor mailing list