Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unpacking a list
#4
You can use oeperator'-' or the difference method
Code:
print('\nThis program will print out a set containing all colors from color_list_1 {"White", "Black", "Red"} that are not present in color_list_2 {"Red", "Green"}.')
color_list_1 = set(["White", "Black", "Red"])
color_list_2 = set(["Red", "Green"])
print(color_list_1 - color_list_2)
print(color_list_1.difference(color_list_2))
Output:
Quote:This program will print out a set containing all colors from color_list_1 {"White", "Black", "Red"} that are not present in color_list_2 {"Red", "Green"}.
{'Black', 'White'}
{'Black', 'White'}
Mark17 likes this post
Reply


Messages In This Thread
Unpacking a list - by Mark17 - Dec-17-2020, 03:44 PM
RE: Unpacking a list - by stranac - Dec-17-2020, 03:58 PM
RE: Unpacking a list - by snippsat - Dec-17-2020, 05:12 PM
RE: Unpacking a list - by aajkaal - Dec-18-2020, 05:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unpacking a dict with * or ** msrk 4 1,097 Dec-02-2023, 11:50 PM
Last Post: msrk
  iterate through the dict_values while unpacking the dictionary PeacockOpenminded 3 1,394 Jan-22-2023, 12:44 PM
Last Post: PeacockOpenminded
  Unpacking zip object Mark17 12 3,449 Mar-28-2022, 04:59 PM
Last Post: deanhystad
  unpacking list wardancer84 2 1,935 Sep-11-2021, 02:42 PM
Last Post: wardancer84
  unpacking tuple not working project_science 1 1,559 Jan-09-2021, 09:09 PM
Last Post: buran
  Unpacking wheel files DavidTheGrockle 3 12,100 Dec-15-2020, 05:11 PM
Last Post: DavidTheGrockle
  Why the result of "extended iterable unpacking" with set() is unpredictable? zohanlin 2 2,150 Jun-29-2020, 10:30 AM
Last Post: zohanlin
  Unpacking nested lists yonatan776 1 2,258 Apr-14-2020, 08:50 PM
Last Post: buran
  Unpacking dictionary from .xlsx as Kwargs etjkai 5 2,977 Dec-27-2019, 05:31 PM
Last Post: etjkai
  Tuple Unpacking HarshaliPatel 3 2,933 Jan-30-2019, 12:42 PM
Last Post: dukoolsharma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020