Skip to content

suggested improvements t- more efficient and more pythonic #7

@quentinjs

Description

@quentinjs

These 2 functions could be significantly improved.

  1. instead of returning a list with one dict entry each, just return a single dictionary with all the entries
    i used the following to quickly convert them into a proper dict
    d = {}
    for r in parsedAddress:
    key = list(r.keys())[0]
    value = list(r.values())[0]
    d[key] = value

  2. use text = re.sub('[àáâãăäāå]', '', text) it will be much faster

And where are the other functions from the library ?

def stringToJSON(string):
if not string in ['{}']:
string = string.replace('{ ', '')
string = string.replace('}', '')
string = string.replace('"', '')
string = string.split(", ")
stringList = [i.split(': ') for i in string]
outDictList = []
for i in stringList:
outDictList.append({i[0]: i[1].rstrip().lstrip()})
return outDictList
else:
return {}

def removeSpeacialChars(address):
b = {'≈': '', '≠': '', '>': '', '<': '', '+': '', '≥': '', '≤': '', '±': '', '*': '', '÷': '', '√': '',
'°': '', '⊥': '', '~': '', 'Δ': '', 'π': '', '≡': '', '≜': '', '∝': '', '∞': '', '≪': '', '≫': '',
'⌈': '', '⌉': '', '⌋': '', '⌊': '', '∑': '', '∏': '', 'γ': '', 'φ': '', '⊃': '', '⋂': '', '⋃': '',
'μ': '', 'σ': '', 'ρ': '', 'λ': '', 'χ': '', '⊄': '', '⊆': '', '⊂': '', '⊇': '', '⊅': '', '⊖': '',
'∈': '', '∉': '', '⊕': '', '⇒': '', '⇔': '', '↔': '', '∀': '', '∃': '', '∄': '', '∴': '', '∵': '',
'ε': '', '∫': '', '∮': '', '∯': '', '∰': '', 'δ': '', 'ψ': '', 'Θ': '', 'θ': '', 'α': '', 'β': '',
'ζ': '', 'η': '', 'ι': '', 'κ': '', 'ξ': '', 'τ': '', 'ω': '', '∇': ''}
for x, y in b.items():
address = address.replace(x, y)
return address

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions