-2

I am new to coding in Python and ran into an issue. I have a list of domain names that I would like to get whois lookup information of. I am using a for look to get whois information on every domain in the list called domain_name like this:

for i in domain_name:
    print(whois.whois(i))

I am getting the results printed just fine. But I would like to save those results in a variable that I can make a list of dataframe out of. How do I go about doing that?

thank you!

ewokx
  • 2,204
  • 3
  • 14
  • 27
grandi
  • 1
  • 2

2 Answers2

2

A list comprehension is appropriate here, useful if you are starting with one list and want to create a new one.

my_results = [whois.whois(i) for i in domain_name]

Will create a new list with the whois results.

Zhenhir
  • 1,157
  • 8
  • 13
0

Define the list you want to store them in before the loop then append them to it inside the loop:

my_container = []
for domain in domain_names:
   my_container.append(whois.whois(domain))
Ari Cooper-Davis
  • 3,374
  • 3
  • 26
  • 43
  • 1
    Thank you so much!!! I really appreciate you prompt response. Your answer did exactly what I wanted. Here's the code: my_container = [] for domain in domain_names: my_container.append(whois.whois(domain)) I got all the results for every domain name in my list saved into my_container list. – grandi Jan 31 '22 at 00:06