# -*- coding: utf-8 -*-
"""disconv1.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1lbh_V9nG082forVjXRzRoP2TEfgRxDHS
"""

class checks:
  def __init__(self):
    self.dton={int:int,str:ord,float:int,bool:int}
    self.dtofl={int:float,str:ord,float:float,bool:float}
    self.dtostr={str:str,int:str,float:str,bool:str}

ch=checks()

def trueaggr(a):
    if(type(a)==bool):
      return(bool)
    else:
      l=str(a).split('.')
      if(l[0]==str(a)):
        if(str(a).isdigit()):
          return(int)
        else:
          return(str)
      elif(len(l)==2):
        if(str(l[0]).isdigit()) and (str(l[1]).isdigit()) :
          return(float)
        else:
          return(str)
      else:
        return(str)
  
def tostr(x):
    if type(x)==list:
      return(ltos(x))
    elif(type(x)==dict):
      return(dtos(x))
    elif(type(x)==set):
      return(stos(x))
    elif(type(x)==tuple):
      return(tuptos(x))
    else:
      return None

def ltos(l):
    for i in range(len(l)):
      temp=tostr(l[i])
      if not(temp==None):
        l[i]=temp
      else:
        l[i]=str(l[i])
    return(l)
  
def dtos(D,target='values'):
    if(target=='values'):
      extract=ltos(list(D.values()))
      c=0
      for i in D.keys():
        D[i]=extract[c]
        c+=1
    else:
      extract=ltos(list(D.keys()))
      c=0
      val=list(D.values())
      D={}
      for i in range(len(val)):
        D[extract[i]]=val[i]
    return(D)
  
def tuptos(t):
    return(tuple(ltos(list(t))))

def stos(s):
    extract=ltos(list(s))
    return(set(extract))

  

def tofloat(x):
    if(type(x)==list):
      return(ltof(x))
    elif(type(x)==dict):
      return(dtof(x))
    elif(type(x)==set):
      return(stof(x))
    elif(type(x)==tuple):
      return(tuptof(x))


def ltof(l):
    for i in range(len(l)):

        if (type(l[i]) == list):
            l[i] = ltof(l[i])
        elif (type(l[i]) == dict):
            l[i] = dtof(l[i])
        elif (type(l[i]) == set):
            l[i] = stof(l[i])
        elif (type(l[i]) == tuple):
            l[i] = tuptof(l[i])
        else:
            actyp = trueaggr(l[i])
            if (not (actyp == str)):

                l[i] = ch.dtofl[actyp](actyp(l[i]))
            else:
                temp = l[i]
                l[i] = []
                for j in temp:
                    l[i] += [float(ord(j))]
    return (l)
  
def dtof(D,target='values'):
    if target=='values':
      extract=ltof(list(D.values()))
      c=0
      for i in D.keys():
        D[i]=extract[c]
        c+=1
    else:
      extract=ltof(list(D.keys()))
      c=0
      val=list(D.values())
      D={}
      for i in range(len(val)):
        if type(extract[i]) == list:
          D[tuple(extract[i])]=val[i]
        else:
          D[extract[i]]=val[i]
    return(D)
  
def tuptof(t):
    return(tuple(ltof(list(t))))

def stof(s):
    extract=ltof(list(s))
    for i in range(len(extract)):
      if(type(extract[i])==list):
        extract[i]=tuple(extract[i])
    return(set(extract))



def tonum(x):
    if(type(x)==list):
      return(ltonum(x))
    elif(type(x)==dict):
      return(dtonum(x))
    elif(type(x)==set):
      return(stonum(x))
    elif(type(x)==tuple):
      return(tuptonum(x))


def ltonum(l):
    for i in range(len(l)):
      if (type(l[i])==list):
        l[i]=ltonum(l[i])
      elif(type(l[i])==dict):
        l[i]=dtonum(l[i])
      elif(type(l[i])==set):
        l[i]=stonum(l[i])
      elif(type(l[i])==tuple):
        l[i]=tuptonum(l[i])
      else:
        actyp=trueaggr(l[i])
        try:
          l[i]=ch.dton[actyp](actyp(l[i]))
        except:
          temp=l[i]
          l[i]=[]
          for j in temp:
            l[i]+=[ord(j)]
    return(l)
  
def dtonum(D,target='values'):
    if target=='values':
      extract=ltonum(list(D.values()))
      c=0
      for i in D.keys():
        D[i]=extract[c]
        c+=1
    else:
      extract=ltonum(list(D.keys()))
      c=0
      val=list(D.values())
      D={}
      for i in range(len(val)):
        if type(extract[i]) == list:
          D[tuple(extract[i])]=val[i]
        else:
          D[extract[i]]=val[i]
    return(D)
  
def tuptonum(t):
    return(tuple(ltonum(list(t))))

def stonum(s):
    extract=ltonum(list(s))
    for i in range(len(extract)):
      if(type(extract[i])==list):
        extract[i]=tuple(extract[i])
    return(set(extract))