2

can you please help me with this.
I'm creating dataset of [Leet words][1].
This code is for generating [Leet words][1]. it is working fine with less number of strings but I've nearly 3,800+ strings and my pc is not capable to do so. I've Tried to run this on cloud(30gb RAM) not worked for me. but I think possible solution is to convert this code into numpy but I don't know how. if you know any other efficient way to do this it will be helpful.
Thanks!

from itertools import product
import pandas as pd
REPLACE = {'a': '@', 'i': '*', 'o': '*', 'u': '*', 'v': '*',
'l': '1', 'e': '*', 's': '$', 't': '7'}

def Leet2Combos(word):
possibles = []
for l in word.lower():
ll = REPLACE.get(l, l)
possibles.append( (l,) if ll == l else (l, ll) )
return [ ''.join(t) for t in product(*possibles) ]
s="""india
love
USA"""

words = s.split('\n')
print(words)
lst=[]
# ['india', 'love', 'USA']
for word in words:
lst.append(Leet2Combos(word))
k = pd.DataFrame(lst)
k.head()

Comments
  • 4
    Have you calculated the complexity / theoretic resource demand / scalability of your algorithm¹?
    Using numpy won't change this.

    ¹: Those terms are not exactly equal, but I hope younger what I mean.
  • 1
  • 1
    the implementaion is a bit ineffizient. Since you want to translate characters of a string with others, i recommend you to look up the str.translate method¹. Its more space efficient than when you want to replace all mapped characters.

    ¹https://docs.python.org/3/library/...
Add Comment