About 539,000 results
Open links in new tab
  1. Difference between dict and set (python) - Stack Overflow

    Dec 19, 2015 · Use set() for empty sets, use {} for empty dicts, use {genexp} for set comprehensions/displays, use {1,2,3} for explicit set literals, and use {k1:v1, k2:v2} for dict …

  2. What's the difference between a dictionary and a set? : r ... - Reddit

    The set is a dictionary without values. Before sets, it was common to use dicts with empty values to get the same properties.

  3. How does python know if it is an empty set vs. a dictionary?

    Apr 13, 2022 · For example, if one is iterating using a for-loop, how would python know given that the syntax is similar: set = {} vs dict = {}? Is it because one is a sequence while the other is …

  4. Difference between Set and Dictionary in Python - Tpoint Tech

    May 9, 2025 · Usually, the set () function is used to generate an empty set, and {} is used to create an empty dictionary. Unordered: Elements in a set do not have any particular order. …

  5. Initializer for set, like dict - Discussions on Python.org

    Dec 4, 2024 · Also set comprehension uses {} as a dict: And for comprehension it would look like so: And this would make differentiating between a dict and a set easier, especially when …

  6. Python Dict and Set: A Comprehensive Guide - CodeRivers

    Apr 12, 2025 · In Python, dictionaries (`dict`) and sets (`set`) are two powerful and widely used data structures. Dictionaries are unordered collections of key - value pairs, which are …

  7. Creating Empty Lists, Dictionaries, and Sets in Python

    Sep 28, 2024 · Learn how to create empty lists, dictionaries, and sets in Python with this easy guide. Understand their uses and differences.

  8. How do you differentiate between declaring an empty dictionary

    Jun 23, 2016 · A little correction to @Colin information, empty sets are not defined with brackets, but rather curly brackets with the name set prepended as below: For dictionary my_dictionary …

  9. python - Empty set literal? - Stack Overflow

    Apr 15, 2017 · If you want to make an existing set empty, you can use the .clear() metod, especially if you want to avoid creating a new object. If you want to do a comparison, use set() …

  10. Why in Python do you have to create a set with the set ... - Reddit

    Nov 9, 2022 · A lot of answers are simply pointing out what you already know: {} makes an empty dictionary and not a set. The historical reason for this is that the dictionary very much predates …

  11. Some results have been removed
Refresh