About 1,070,000 results
Open links in new tab
  1. What is the difference between sets and lists in Python?

    Sep 10, 2012 · Difference Between Sets and Lists Here we will discuss the difference between Sets and List in Python. Lists 1) Lists save elements in the order they are inserted. 2) Lists support indexing. 3) We can change the value of the element stored in the lists. 4) Lists can store duplicate values. 5) Lists are declared using square brackets.

  2. Python Sets vs Lists - Stack Overflow

    Aug 12, 2019 · Sets are also sequence structures but with two differences from lists and tuples. Although sets do have an order, that order is arbitrary and not under the programmer’s control. The second difference is that the elements in a set must be unique. set by definition. [python | wiki]. >>> x = set([1, 1, 2, 2, 3, 3]) >>> x {1, 2, 3}

  3. In Python, when to use a Dictionary, List or Set?

    Jul 1, 2019 · list - if you require an ordered sequence of items. dict - if you require to relate values with keys. set - if you require to keep unique elements. Detailed Explanation List. A list is a mutable sequence, typically used to store collections of homogeneous items. A list implements all of the common sequence operations: x in l and x not in l; l[i ...

  4. python - Compute list difference - Stack Overflow

    The above examples trivialized the problem of calculating differences. Assuming sorting or de-duplication definitely make it easier to compute the difference, but if your comparison cannot afford those assumptions then you'll need a non-trivial implementation of a diff algorithm.

  5. python find difference between two lists - Stack Overflow

    Mar 21, 2014 · If you want a set of items in either list but not both lists use the symmetric difference operator '^'. [1,2,3,4,5] ^ [3,4,5,6,7] = [1,2,6,7] The symmetric difference operator, assuming it does what you want, also has the advantage of being commutative.

  6. Get difference between two lists with Unique Entries

    The existing solutions all offer either one or the other of: Faster than O(n*m) performance. Preserve order of input list.

  7. python - What's the difference between lists and tuples ... - Stack ...

    Dec 9, 2024 · The main difference between mutable and immutable is memory usage when you are trying to append an item. When you create a variable, some fixed memory is assigned to the variable. If it is a list, more memory is assigned than actually used. E.g. if current memory assignment is 100 bytes, when you want to append the 101th byte, maybe another 100 ...

  8. What is the difference between Set and List? - Stack Overflow

    Jun 23, 2009 · The main difference between List and Set is that List allows duplicates while Set doesn't allow duplicates. Order List is an ordered collection it maintains the insertion order, which means upon displaying the list content it will display the elements in the same order in which they got inserted into the list.

  9. What are differences between List, Dictionary and Tuple in Python ...

    Sep 6, 2010 · A list can store a sequence of objects in a certain order such that you can index into the list, or iterate over the list. List is a mutable type meaning that lists can be modified after they have been created. A tuple is similar to a list except it is immutable. There is also a semantic difference between a list and a tuple. To quote Nikow's ...

  10. How to compare a list of lists/sets in python? - Stack Overflow

    first_set = set(map(tuple, first_list)) secnd_set = set(map(tuple, secnd_list)) Note: map is a functional programming command that applies the function in the first argument (in this case the tuple function) to each item in the second argument (which in our case is a list of lists). and find the symmetric difference between the sets: >>> first ...

Refresh