''' Author : Sapan Singh Email : sapansingh43@gmail.com ''' def main(): dct ={ "U4V6Y3USKUYCB6Q5" : { "U4V6Y3USKUYCB6Q5.6QCMYABX3D" : { "offerTermCode" : "6QCMYABX3D", "sku" : "U4V6Y3USKUYCB6Q5", "effectiveDate" : "2016-05-31T23:59:59Z", "priceDimensions" : { "U4V6Y3USKUYCB6Q5.6QCMYABX3D.2TG2D8R56U" : { "rateCode" : "U4V6Y3USKUYCB6Q5.6QCMYABX3D.2TG2D8R56U", "description" : "Upfront Fee", "unit" : "Quantity", "pricePerUnit" : { "USD" : "34800" }, "appliesTo" : [ ] }, "U4V6Y3USKUYCB6Q5.6QCMYABX3D.6YS6EN2CT7" : { "rateCode" : "U4V6Y3USKUYCB6Q5.6QCMYABX3D.6YS6EN2CT7", "description" : "USD 0.0 per Redshift, dw2.8xlarge reserved instance applied", "beginRange" : "0", "endRange" : "Inf", "unit" : "Hrs", "pricePerUnit" : { "USD" : "0.0000000000" }, "appliesTo" : [ ] } }, "termAttributes" : { "LeaseContractLength" : "1yr", "OfferingClass" : "standard", "PurchaseOption" : "All Upfront" } } , "U4V6Y3USKUYCB6Q5.4NA7Y494T4" : { "offerTermCode" : "4NA7Y494T4", "sku" : "U4V6Y3USKUYCB6Q5", "effectiveDate" : "2016-09-30T23:59:59Z", "priceDimensions" : { "U4V6Y3USKUYCB6Q5.4NA7Y494T4.6YS6EN2CT7" : { "rateCode" : "U4V6Y3USKUYCB6Q5.4NA7Y494T4.6YS6EN2CT7", "description" : "Redshift, dw2.8xlarge reserved instance applied", "beginRange" : "0", "endRange" : "Inf", "unit" : "Hrs", "pricePerUnit" : { "USD" : "4.8650000000" }, "appliesTo" : [ ] } }, "termAttributes" : { "LeaseContractLength" : "1yr", "OfferingClass" : "standard", "PurchaseOption" : "No Upfront" } }, "U4V6Y3USKUYCB6Q5.HU7G6KETJZ" : { "offerTermCode" : "HU7G6KETJZ", "sku" : "U4V6Y3USKUYCB6Q5", "effectiveDate" : "2016-05-31T23:59:59Z", "priceDimensions" : { "U4V6Y3USKUYCB6Q5.HU7G6KETJZ.2TG2D8R56U" : { "rateCode" : "U4V6Y3USKUYCB6Q5.HU7G6KETJZ.2TG2D8R56U", "description" : "Upfront Fee", "unit" : "Quantity", "pricePerUnit" : { "USD" : "12600" }, "appliesTo" : [ ] }, "U4V6Y3USKUYCB6Q5.HU7G6KETJZ.6YS6EN2CT7" : { "rateCode" : "U4V6Y3USKUYCB6Q5.HU7G6KETJZ.6YS6EN2CT7", "description" : "Redshift, dw2.8xlarge reserved instance applied", "beginRange" : "0", "endRange" : "Inf", "unit" : "Hrs", "pricePerUnit" : { "USD" : "2.6125000000" }, "appliesTo" : [ ] } }, "termAttributes" : { "LeaseContractLength" : "1yr", "OfferingClass" : "standard", "PurchaseOption" : "Partial Upfront" } }, "U4V6Y3USKUYCB6Q5.38NPMPTW36" : { "offerTermCode" : "38NPMPTW36", "sku" : "U4V6Y3USKUYCB6Q5", "effectiveDate" : "2016-05-31T23:59:59Z", "priceDimensions" : { "U4V6Y3USKUYCB6Q5.38NPMPTW36.2TG2D8R56U" : { "rateCode" : "U4V6Y3USKUYCB6Q5.38NPMPTW36.2TG2D8R56U", "description" : "Upfront Fee", "unit" : "Quantity", "pricePerUnit" : { "USD" : "22050" }, "appliesTo" : [ ] }, "U4V6Y3USKUYCB6Q5.38NPMPTW36.6YS6EN2CT7" : { "rateCode" : "U4V6Y3USKUYCB6Q5.38NPMPTW36.6YS6EN2CT7", "description" : "Redshift, dw2.8xlarge reserved instance applied", "beginRange" : "0", "endRange" : "Inf", "unit" : "Hrs", "pricePerUnit" : { "USD" : "1.1400000000" }, "appliesTo" : [ ] } }, "termAttributes" : { "LeaseContractLength" : "3yr", "OfferingClass" : "standard", "PurchaseOption" : "Partial Upfront" } }, "U4V6Y3USKUYCB6Q5.NQ3QZPMQV9" : { "offerTermCode" : "NQ3QZPMQV9", "sku" : "U4V6Y3USKUYCB6Q5", "effectiveDate" : "2016-05-31T23:59:59Z", "priceDimensions" : { "U4V6Y3USKUYCB6Q5.NQ3QZPMQV9.2TG2D8R56U" : { "rateCode" : "U4V6Y3USKUYCB6Q5.NQ3QZPMQV9.2TG2D8R56U", "description" : "Upfront Fee", "unit" : "Quantity", "pricePerUnit" : { "USD" : "48620" }, "appliesTo" : [ ] }, "U4V6Y3USKUYCB6Q5.NQ3QZPMQV9.6YS6EN2CT7" : { "rateCode" : "U4V6Y3USKUYCB6Q5.NQ3QZPMQV9.6YS6EN2CT7", "description" : "USD 0.0 per Redshift, dw2.8xlarge reserved instance applied", "beginRange" : "0", "endRange" : "Inf", "unit" : "Hrs", "pricePerUnit" : { "USD" : "0.0000000000" }, "appliesTo" : [ ] } }, "termAttributes" : { "LeaseContractLength" : "3yr", "OfferingClass" : "standard", "PurchaseOption" : "All Upfront" } } }} print(dct['U4V6Y3USKUYCB6Q5'].keys()) print(removedots(dct)) print(dct['U4V6Y3USKUYCB6Q5'].keys()) def removedots(dct): for i in dct: if type(dct[i]) == dict: dct[i] = removedots(dct[i]) if '.' in i: dct[i.rsplit('.', 1)[1]] = dct.pop(i) return dct if __name__ == '__main__': main()