What is the difference between sets and lists in Python?

前端 未结 7 642
终归单人心
终归单人心 2020-11-29 19:14

Is the only difference between sets and lists in Python the fact that you can use the union, intersect, difference, symmetric difference functions to compare two sets? Why c

相关标签:
7条回答
  • 2020-11-29 20:09

    Some more differences are:

    1. List can be 2-D whereas a set can't.
    2. As list are ordered (IE. have serial number) list are comparatively slow to execute whereas sets are fast.
    3. List in python is like Array of java or c.
    4. Printing a set almost always provide different sequence of output.
    5. Set uses hash function to find an element whereas list is an array. Hence finding element in Set is faster than in list.
    0 讨论(0)
提交回复
热议问题