Use isinstance to make it work for subclasses of dict and list

By using isinstance it'll also work for subclasses of list and dict.