About 219,000 results
Open links in new tab
  1. How to construct a set out of list items in python?

    Nov 27, 2016 · to create a list from a set. Just note that the order of the elements in a list is generally lost when converting the list to a set since a set is inherently unordered. (One exception in CPython, though, seems to be if the list consists only of non-negative integers, but I assume this is a consequence of the implementation of sets in CPython ...

  2. Use curly braces to initialize a Set in Python - Stack Overflow

    From Python 3 documentation (the same holds for python 2.7): Curly braces or the set() function can be used to create sets. Note: to create an empty set you have to use set(), not {}; the latter creates an empty dictionary, a data structure that we discuss in the next section. in python 2.7:

  3. python - Empty set literal? - Stack Overflow

    Apr 15, 2017 · By all means, please use set() to create an empty set. But, if you want to impress people, tell them that you can create an empty set using literals and * with Python >= 3.5 ( see PEP 448 ) by doing:

  4. How to clone or copy a set in Python? - Stack Overflow

    Apr 21, 2014 · shallow_copy_of_set = set(old_set) Or: shallow_copy_of_set = old_set.copy() #Which is more readable. The reason that the first way above doesn't give a set of a set, is that the proper syntax for that would be set([old_set]). Which wouldn't work, because sets can't be elements in other sets

  5. How can I create a Set of Sets in Python? - Stack Overflow

    TypeError: unhashable type: 'set' Is it possible to have a set of sets in Python? I am dealing with a large collection of sets and I want to be able to not have to deal duplicate sets (a set B of sets A1, A2, ...., An would "cancel" two sets if Ai = Aj)

  6. How to set environment variables in Python? - Stack Overflow

    os.environ behaves like a python dictionary, so all the common dictionary operations can be performed. In addition to the get and set operations mentioned in the other answers, we can also simply check if a key exists. The keys and values should be stored as strings. Python 3. For python 3, dictionaries use the in keyword instead of has_key

  7. python - Create a set from a series in pandas - Stack Overflow

    some_series.unique() gives every unique item in the series = basically a set. Creating a set from a set is fast because you have no duplicates --> less items to work on --> less work to do --> fast. Pandas is mostly C under the hood, maybe set() is not that optimized compared to .unique()?

  8. python - Making a set from dictionary values - Stack Overflow

    Dec 2, 2014 · Your dict uses a hash table exactly the same way as wim's set, except that yours also fills in the values of that hash table for no reason. If you want an actual "another way", you can, e.g., sort and throw away equal adjacent values (which might be useful if, e.g., the values weren't hashable—although given that the OP wants a set, that can ...

  9. Creating Set of objects of user defined class in python

    Jul 5, 2013 · Table is a set which is unordered list, which should not have duplicate objects. Help: is there any way in this set up I can add the object only when it's not in the table. python

  10. python - making a new set using for loop, in one line - Stack …

    Oct 22, 2017 · one of the nice things about python is that you can read it as if you're reading a sentence from a book: so i for i in nums if i not in unwanted means that you iterate nums and for each i in nums you'll collect it only if it's not in unwanted