Reputation: 49
I have different lists that i want to get the last character of the last element out of. I currently have this code:
happy = True
pile1=["vapor","Tie"]
pile2=["stone","he"]
pile3=["glass","sto"]
piles=pile1,pile2,pile3
print([pile[-1][-1] for pile in piles])
The problem with this code is that it only tells me what the last elements of all the lists final string/element is. I need it to say if there are only unique elements. If there are only unique element True statement should turn false. This also needs to work if one of the lists are suddenly empty. i know the slicing wont work while a list is empty, so what should i do?
What i mean by if all the elements are unique is that my statement that is for this example happy, should go to false. Like this:
happy = True
pile1 = ["vapor", "Ti"]
pile2 = ["stone", "he"]
pile3 = ["glass", "stov"]
piles = pile1, pile2, pile3
print([pile[-1][-1] for pile in piles])
Output: ['i', 'e', 'v'] Since thare are ONLY unique elements the statement should be made false
happy = False
Upvotes: 0
Views: 63
Reputation: 16147
You could check the length of unique letters versus the number of elements.
happy = len(set([pile[-1][-1] for pile in piles])) != len(piles)
Upvotes: 1