def to_query_str(params, comma_delimited_lists=True, prefix=True):
 if (not params):
  return ''
 query_str = ('?' if prefix else '')
 for (k, v) in params.items():
  if (v is True):
   v = 'true'
  elif (v is False):
   v = 'false'
  elif isinstance(v, list):
   if comma_delimited_lists:
    v = ','.join(map(str, v))
   else:
    for list_value in v:
     if (list_value is True):
      list_value = 'true'
     elif (list_value is False):
      list_value = 'false'
     else:
      list_value = str(list_value)
     query_str += (((k + '=') + list_value) + '&')
    continue
  else:
   v = str(v)
  query_str += (((k + '=') + v) + '&')
 return query_str[:(-1)]

def to_query_str ( params , comma_delimited_lists = True , prefix = True ) : if ( not params ) : return '' query_str = ( '?' if prefix else '' ) for ( k , v ) in params . items ( ) : if ( v is True ) : v = 'true' elif ( v is False ) : v = 'false' elif isinstance ( v , list ) : if comma_delimited_lists : v = ',' . join ( map ( str , v ) ) else : for list_value in v : if ( list_value is True ) : list_value = 'true' elif ( list_value is False ) : list_value = 'false' else : list_value = str ( list_value ) query_str += ( ( ( k + '=' ) + list_value ) + '&' ) continue else : v = str ( v ) query_str += ( ( ( k + '=' ) + v ) + '&' ) return query_str [ : ( - 1 ) ]
converts a dictionary of parameters to a query string .