Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Python by registered user __SMRITI__ ( 1 year ago )
from collections import defaultdict
dic = defaultdict(list)


#reading the lines
with open('jsimeq.txt') as f:
    lines = [line.rstrip()  for line in f if line!='']
  
#print(lines)

for line in lines:
    #removing blank lines
    if line!='':
        line=line.replace("exp",'')
        #seperating LHS and RHS
        ls=line.split("=")
        key=ls[0]
        s=''
        #Processing the RHS
        for i in ls[1]:
            #Replace all Arithematical Symbols with '@'
            if i in "+-/*":
                s+='@'
                continue
            # remove the Parenthesis
            if i not in " ([])":
                s+=i
        #print(s)

        #sperate all the variables in RHS basis '@'
        sl=s.split("@")
        #print(sl)

        #Removing any constant present in the list
        val= list(set([i for i in sl if i not in "0123456789"]))
        #print(val)

        # check if the given LHS is already present in the dictionary
        if len(dic[key])>0 and dic[key][-1]=='':
            dic[key][-1]=val
        else:
            for i in val:
                dic[key].append(i)


print(dic)
for key,val in dic.items():
    print(key," ",val)

 

Revise this Paste

Parent: 123875
Your Name: Code Language: