Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
confusion with hashable
#6
If you have a set s = {1, 2, 3} and ask for s[0] you will get an error. Sets are unordered and indexing implies that the thing being indexed has an order. You can iterate over the set, but don't expect the order of items to be the same as the order the items were added to the set. The items will be ordered by hash value.

When trying to create a set of lists, the problem is, as mentioned previously, that lists are not hashable. You cannot create a set of lists. Now your program has two errors. You are trying to make a set that contains items that are not hashable, and you are trying to index a set which is not a valid operation. The unhashable type error occurs first, so that is the one that gets reported.

I try to only use sets when I want to do set operations. Otherwise there are too many limitations with sets.
Reply


Messages In This Thread
confusion with hashable - by spalisetty06 - Aug-20-2020, 02:41 PM
RE: confusion with hashable - by buran - Aug-20-2020, 02:46 PM
RE: confusion with hashable - by spalisetty06 - Aug-20-2020, 03:40 PM
RE: confusion with hashable - by spalisetty06 - Aug-21-2020, 01:11 PM
RE: confusion with hashable - by ndc85430 - Aug-21-2020, 02:27 PM
RE: confusion with hashable - by deanhystad - Aug-21-2020, 07:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  hashable confusion spalisetty06 3 2,005 Aug-16-2020, 03:54 PM
Last Post: spalisetty06

Forum Jump:

User Panel Messages

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