To prove that a little knowledge is a little stupid or something to that effect:
# for key in key_list: # print(key) # if key not in key_list0: # print("Error:", key, "not available, start again") # get_new_list = True # break # else: get_new_list = False Assume key_list0 = [('a', 'Ask'), ('y', 'Dividend Yield')] The above worked when key_list was 'a y' or 'hhh' Well, if a little cool was good why not use all of my new found knowledge of comprehensions. So I head down the path of all sorts of variations of the following. And I mean all sorts. Instead of [reenter, key_columns] I used a single list. Instead of the exec('reenter = True') I used a simple reenter=True (and an eval and compile which I don't totally understand yet). Turns out that python doesn't seem to like an assignment in the overall if clause - error. Weird thing, entering a y would make the final print spit out (False, 'a') (False, 'o') but the entry of hhh caused the final print to spit out [] (in the best of the various experiments. Which I don't quite understand. The reason is because I set up the if statement to be True either way. With an a it would go thru and create the proper output. But with hhh the print prints out the Error:.., and I was hoping the assignment of True to reenter would create a True which would make it out to the while. But it won't. I think I have to just stay with the more verbose as above. Besides after trying so many variations the comprehension was getting rather kluge:<)) But really grok comprehension a lot better. reenter=True while reenter: reenter=False key_list = input('Please enter space separated keys in the order you want: ').split() [reenter, key_columns ]=[(reenter, key) for key in key_list if ((key in key_list0)) or (print("Error:", key, "not available, start again") and exec('reenter = True', ))] print(reenter,key_columns) Clayton You can tell the caliber of a man by his gun--c. kirkwood
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor