Difference between Set and List in PythonIn this article, we will discuss the difference between Set and list in Python. Set and list are the Data Structures in Python, which are used for storing and organizing the data in an effective manner. ListThe list in Python is like an array of dynamic size, which can be declared in different languages such as vector in C++ language and ArrayList in Java language. It is not compulsory for a list in Python to be homogenous, and this characteristic of the list makes it one of the powerful tools of Python. The following are the important characteristics of list:
Example: Output: JavaTpoint data List: [] The JavaTpoint List of numbers: [12, 24, 64, 18, 3, 201, 65, 35, 27, 29, 58, 42, 87, 30, 28, 79, 4, 90] List Items: let's Python learn JavaTpoint from List1 = [9, 3, 6, 19, 67, 'Hey', 'JavaTpoint', 78, 2, 1] List2 = [9, 3, 6, 19, 67, 78, 'Hey', 'JavaTpoint', 2, 1] False SetSets are the unordered collection of data types in Python, which are mutable and iterable. Sets do not have any repetition of identical elements. One of the major advantages of using sets data storing tool in Python over List is that it offers highly optimized methods for checking the presence of specific items present in the set. The following are the important characteristics of set:
Example: Output: Intial JavaTpoint Set: set() Storing the set by using the Object: {'t', 'v', 'a', 'r', 'T', 'l', 'n', 'y', 'e', ' ', 'h', 'P', 'p', 'f', 'o', 's', 'i', 'J', 'm'} Storing the set by using the List: {'JavaTpoint', "let's", 'learn', 'from', 'Python'} Lists vs. Sets
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week