[Tutor] Print Help

delegbede at dudupay.com delegbede at dudupay.com
Wed Dec 29 13:49:15 CET 2010


I want to loop over a list and then print out a one statement that carries all the items in the list e.g

def checking(responses):

        ''' Converts strings that look like A2C3D89AA90 into
            {'A':'2', 'C':'3', 'D':'89', 'AA':'90'}'''

        responses=dict(re.findall(r'([A-Z]{1,2})([0-9]+)', responses.upper())) if responses else {}
        for key in responses.keys():
                count = []
                if key in ['A'] and int(responses[key]) not in range(1,3): count += key
                elif key in ['B', 'G', 'T', 'U', 'V', 'W', 'X'] and int(responses[key]) not in range(1, 3): count += key
                elif key in ['H', 'J', 'K', 'M', 'N', 'P', 'Q','R','S'] and int(responses[key]) not in range(1, 6): count += key
                elif key in ['D', 'E'] and int(responses[key]) == 4: print 'accepted'
                for err in count:
                        count = ", ".join(count)
                   
            print "Invalid Message: You specified out of range values for %s" % (", ".join(count))  

What I am expecting is:
Invalid Message: You specified out of range values for a,s,d,r,t,u

Assuming those were the values that are incorrect. 

Ple help. 

Sent from my BlackBerry wireless device from MTN


More information about the Tutor mailing list