0

I have two lists, master_list, and list_to_be_compared, found the solution to compare lists on python, and it was working for me, but I can't store the output of that inside another list.

master_list = ['n0', 'n1', 'n2', 'n3', 'n4', 'n5', 'n6', 'n7', 'n8', 'n9', 'n10', 'n11', 'n12', 'n13', 'n14', 'n15', 'n16', 'n17', 'n18', 'n19']

list_to_be_compared = ['n1', 'n3', 'n7', 'n8', 'n9', 'n16', 'n17', 'n18']

#TRIAL 1
party = []
party.append(list(set(master_list).intersection(set(list_to_be_compared))))
print(party)

#TRIAL 2
party = list(set(master_list).intersection(set(list_to_be_compared)))
print(party)

It is giving me this output

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-258-3472dc1f0a25> in <module>
----> 1 print(party)

TypeError: 'NoneType' object is not callable

When I just run the file, I am getting the items that are intersecting with the master_list, but how to store it in a list? Thanks for your help :)

Adam
  • 2,820
  • 1
  • 13
  • 33
dips_99
  • 23
  • 4
  • 1
    you assigned `print` to `None` outside of this code block – acushner Jul 23 '20 at 15:07
  • I just run the code and the second attempt is what you need, IDK where is the problem – Brad Figueroa Jul 23 '20 at 15:10
  • no bugs in the code i have run your code and it works fine. – Adam Jul 23 '20 at 15:11
  • @acushner thanks! ```type(print)``` gave me an output ```NoneType```. Should I restart it, or is there a way to reassign? – dips_99 Jul 24 '20 at 03:59
  • nevermind! Found it here - https://stackoverflow.com/questions/17152760/how-to-restore-a-builtin-that-i-overwrote-by-accident – dips_99 Jul 24 '20 at 06:01
  • 1
    that answer will work, but you should use a different name from `print` for the the var where it gets assigned to `None`. basically, don't shadow builtins – acushner Jul 24 '20 at 16:42

0 Answers0