1

I have a List 'SMSStore' which contains a [boolean, string1, string2] eg.

[(False, 'roro', '07189202003'), (False, 'rtptp', '07189202003'), (True, 'rtptp', '07189202003')]

I want to have a function which will loop through the list, check the boolean and return all the string1's of the False booleans.

class SMSMessage(object):

    def __init__(self, hasBeenRead, messageText, fromNumber):
        self.hasBeenRead = hasBeenRead
        self.messageText = messageText
        self.fromNumber = fromNumber


hasBeenRead = False

**def get_unread_messages(hasBeenRead):
    for i in SMSStore[:][0]:
        if hasBeenRead == False:
             return messageText**

1 Answer 1

1

Simple list comprehension for a simple issue:

...

def get_unread_messages(l):
    return [t[1] for t in l if not t[0]]


l = [(False, 'roro', '07189202003'), (False, 'rtptp', '07189202003'), (True, 'rtptp', '07189202003')]
print(get_unread_messages(l))

The output:

['roro', 'rtptp']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.