[Tutor] problem solving with lists
alan.gauld at yahoo.co.uk
alan.gauld at yahoo.co.uk
Fri Mar 18 09:59:58 EDT 2022
On 18 Mar 2022 13:07, marcus.luetolf at bluewin.ch wrote:
>lst = [['a', 'b', 'c'], ['d', 'e', 'f'], ['a', 'b', 'g'], ['b', 'c',
'h']]
>n = len(lst)
>p = 0
>new_lst = []
>while n > 0:
> pair1 = lst[p][0:2]
> pair2 = list(lst[p][0]+ lst[p][2])
> pair3 = lst[p][1:]
> print('pair1:', pair1, 'pair2: ', pair2, 'pair3: ', pair3)
> if pair1 or pair2 or pair3 not in new_lst
I suspect that's not doing what you think. Python sees it as
If pair 1 not empty
Or pair2 not empty
Or pair3 not in newlist
I don't think that's what you want.
BTW why does
For p in lst not work?
It seems to be what you are effectively doing...
Alan G
From my phone, apologies for any typing errors...
More information about the Tutor
mailing list