code: def sortByNamespacePrefix(urisList, nsList):
      
      exit = []
      urisList = sort_uri_list_by_name(urisList)
      for ns in nsList:
          innerexit = []
          for uri in urisList:
              if str(uri).startswith(str(ns)):
                  innerexit += [uri]
          exit += innerexit
  
      # add remaining uris (if any)
      for uri in urisList:
          if uri not in exit:
              exit += [uri]
  
      return exit
docs: Given an ordered list of namespaces prefixes, order a list of uris based on that.
          Eg
  
          In [7]: ll
          Out[7]:
          [rdflib.term.URIRef(u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
           rdflib.term.URIRef(u'printGenericTreeorg/2000/01/rdf-schema#comment'),
           rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'),
           rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#equivalentClass')]
  
          In [8]: sortByNamespacePrefix(ll, [OWL.OWLNS, RDFS])
          Out[8]:
          [rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#equivalentClass'),
           rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#comment'),
           rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'),
           rdflib.term.URIRef(u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type')]