Categories
Python

Check if two dictionaries have same keys in python

I was lazy loading a large json file and wanted to collect only two keys. Running through with ujson I had to check that I had the correct data. I needed to check if my tmp dict was what I wanted. By using set() on a dict you’ll get all the keys and then do […]

Categories
Python Uncategorized

Change a value with configparser for python

configparser is a great module to store configuration information into a filehttps://docs.python.org/2/library/configparser.html a config file could look like this: To load the value from the file To change the value in the file:

Categories
Python Uncategorized

Dictionary changed size during iteration while using pop() in python

Running through a json file remove all keys but one This is fine running python2 but in python3 you will run into this error Calling keys() in python2 makes a copy of the keys that we iterate through. This is not how it works in python3, this returns an iterator instead of a list, hence […]

Categories
Python Uncategorized

Remove non letter characters before and after characters in Python

To remove none letters characters from the beginning and end in python use regex from the re.py library. I needed it to remove spaces as well but not in between the words. Here’s what I did: Output:

Categories
Python

AWS Lambda – name ‘Key’ is not defined

When going through the example from https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Python.04.html I ran into the following error message: The error come from this line The issue was that I was only importing boto3, this is not enough. Guess I have to read the whole tutorial. You’ll have to add the following import.