[Tutor] problem solving with lists
alan.gauld at yahoo.co.uk
alan.gauld at yahoo.co.uk
Fri Mar 18 14:16:04 EDT 2022
On 18 Mar 2022 15:12, marcus.luetolf at bluewin.ch wrote:
…many thanks for your quick replay.
When I used a for loop :
>lst = [['a', 'b', 'c'], ['d', 'e', 'f'], ['a', 'b', 'g'], ['b', 'c',
'h']]
>sub_lst = []
>for p in lst:
> pair1 = lst[p][0:2]
P is not an index its the actual sublist. So you just need
Pair1 = p[0:2]
>
> ected. But I don’t understand
what you mean with
If pair 1 not empty
Or pair2 not empty
Or pair3 not in newlist
What is the difference between pair not beeing empty or not beeing in
new_list ?
Pair not empty means pair contains anything other than the empty list.
Pair not in newlist means pair is not empty and it's contents are not I.
Newlist. Very different!
How should I define the if condition properly ?
You need, I assume,
If Pair1 not in newlist
Or pair2 not in newlist
Or pair3 not in newlist
Alan g.
More information about the Tutor
mailing list