Q2: How to count total values in the same key????

- Code: Select all
`def age_swap():`

reversible_ages={}

moms_age=int(raw_input('enter your moms current age:\t'))

baby_age=int(raw_input('enter your current age:\t'))

expectancy=int(raw_input('for how long your mom\'s age do you want to theoretically want to compare age swap?:\t'))

mom_wen_uborn=moms_age-baby_age

reversible_ages.setdefault('You:Mom', []).append([(baby,imom) for baby,imom in enumerate(xrange(mom_wen_uborn,expectancy)) if str(baby)[:]==str(imom)[::-1]])

ra=[(''.join(str(v).strip())) for k,v in reversible_ages.iteritems()]

count=len(ra) #count=len(list(reversible_ages))

return 'No. of times that happens for is %s' %(count), ''.join(ra) #','.join(str(reversible_ages.keys()))

- Code: Select all
`age_swap()`

enter your moms current age: 73

enter your current age: 37

for how long your mom's age do you want to theoretically want to compare age swap?: 200

Out[66]:

('No. of times that happens for is 1',

'[[(15, 51), (26, 62), (37, 73), (48, 84), (59, 95)]]')