Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sets and Lists
#1
Hi,

Can someone please explain to me why when I enter this in python it does not give an error:

print(set([1,2,3]))

but as soon as I enter this it gives an error saying 'unhashable type'.

print(set(([1,2,3],[4,5,6])))

I understand lists are unhashable and arguments for sets can only be of hashable types.
But in here print(set([1,2,3])) the argument the set is taking is also a list (i.e [1,2,3]) no? so it should also give an error too, right?
Reply
#2
print(set(([1,2,3],[4,5,6])))
would have to be:
print(set([1,2,3]), set([4,5,6]))
retult:
Output:
{1, 2, 3} {4, 5, 6}
sets cannot be list of lists
Reply
#3
thanks, makes sense.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Peculiar pattern from printing of sets SahandJ 7 1,634 Dec-29-2021, 06:31 PM
Last Post: bowlofred
  How does one combine 2 data sets ? detlefschmitt 2 1,675 Sep-03-2021, 03:38 AM
Last Post: detlefschmitt
  Looping Through Large Data Sets JoeDainton123 10 4,354 Oct-18-2020, 02:58 PM
Last Post: buran
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,352 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  comprehension for sets Skaperen 2 1,856 Aug-07-2020, 10:12 PM
Last Post: Skaperen
  Sort sets by item values Sergey 4 66,348 Apr-19-2019, 10:50 AM
Last Post: Sergey
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,246 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Problem with character sets Pedroski55 4 3,702 Mar-04-2019, 02:35 AM
Last Post: snippsat
  merge 3 sql data sets to 1 librairy brecht83 0 2,106 Sep-26-2018, 10:13 PM
Last Post: brecht83

Forum Jump:

User Panel Messages

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