I'm generating domains with random names. I used the map function because it packages the results into a list which I can then join()
into a string but the way I used the lambda function could be confusing to people reading this later.
def generateHost():
charSet = 'abcdefghijklmnopqrstuvwxyz1234567890'
minLength = 5
maxLength = 30
length = random.randint(minLength, maxLength)
return ''.join(map(lambda unused : random.choice(charSet), range(length)))+".com"
This function calls generateHost()
'size' times and creates an array of hosts. I could write it like the above but it would be the same problem. I wrote it with a for
loop which I'm still not satisfied with.
def generateHostList(size):
result = []
for i in range(size):
result += [generateHost()]
return result