how to define following operator/function in python ?
i am new to programming need to define operator/function s^m such that 
***s^m(a^g^n+b^g^o+c^g^p*d^g^q)+a^g^f=a^g^(n+m)+b^g^(o+m)+c^g^(p+m)*d^g^(q+m)+a^g^f***
a b c d g ..all symbols ^=power 
,in simple language operator which will transform all 'g's in bracket to g^m while keeping those out of bracket as it is .


how to define following operator/function in python ?
===

i am new to programming need to define operator/function s^m such that 
***s^m(a^g^n+b^g^o+c^g^p*d^g^q)+a^g^f=a^g^(n+m)+b^g^(o+m)+c^g^(p+m)*d^g^(q+m)+a^g^f***
a b c d g ..all symbols ^=power 
,in simple language operator which will transform all 'g's in bracket to g^m while keeping those out of bracket as it is .

