I am trying to output the sum of consonant and vowel values from a dictionary containing letter_number_pairs as shown below:
vowels = ['a','e','i','o','u']
consonants = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']
letter_number_pairs = {'a': 1,'b': 8,'c': 3,'f': 3,'h': 8,'i': 2,'l': 4,'p': 2,'q': 1,'s': 5,'u': 9,'w': 0,'y': 5,'z': 2}
The question I'm wondering is: "Can I sum the vowel values and sum the consonant values in a single pass?" That is, can I avoid executing two passes of the dictionary as shown in my working example below:
vowel_value_sum = sum(value for (letter, value) in letter_number_pairs.items() if letter in vowels)
consonant_value_sum = sum(value for (letter, value) in letter_number_pairs.items() if letter in consonants)