code: def get_tileset_from_gid(self, gid):
          
          try:
              tiled_gid = self.tiledgidmap[gid]
          except KeyError:
              raise ValueError
  
          for tileset in sorted(self.tilesets, key=attrgetter('firstgid'),
                                reverse=True):
              if tiled_gid >= tileset.firstgid:
                  return tileset
  
          raise ValueError
docs: Return tileset that owns the gid
  
          Note: this is a slow operation, so if you are expecting to do this
                often, it would be worthwhile to cache the results of this.
  
          :param gid: gid of tile image
          :rtype: TiledTileset if found, otherwise ValueError