Can any one help me please to clarify the exact differences between lists, sets, dictionaries, and tuples. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can any one help me please to clarify the exact differences between lists, sets, dictionaries, and tuples.

data structure types

2nd Sep 2017, 11:53 AM
Aseel Najjar
Aseel Najjar - avatar
5 Answers
+ 12
http://thomas-cokelaer.info/tutorials/JUMP_LINK__&&__python__&&__JUMP_LINK/data_structures.html list: sequential data structure where access is made by index x = [1,1,2,3,4,5,5,5] print(x[3]) # outputs 3 tuple: sequential data structure where access is made by index (unlike a list, you cannot modify it content after creation) x = (1,2,3,4,5,6) print(x[1]) # outputs 2 set: data structure which does not contains duplicate values if you take a list [1,1,2,3,4,5,5,5] and cast it to a set the reasult would be [1,2,3,4,5] (another casting back to list is required) x = [1,1,2,3,4,5,5,5] print(list(set(x)) # outputs [1,2,3,4,5] dictionary: hash data structure where access is made by keys x = {"hello": "world", "answer": 42} print(x["hello"]) # outputs "world" print(x["answer"]) # outputs 42
2nd Sep 2017, 12:05 PM
Burey
Burey - avatar
+ 4
!warning! it's true that you can declare a set with using curly brackets, but if you write A={} then A is taken as an empty dictionary (is of type 'dict'). To define an empty set you should write A=set()
2nd Sep 2017, 1:51 PM
m abrate
m abrate - avatar
+ 2
set u can also declair with { } a = {1,2,3,2,5,2,6} print (a) {1,2,3,5,6}
2nd Sep 2017, 1:06 PM
sayan chandra
sayan chandra - avatar
+ 2
@@ Aseel najjer run the code for DETAILED EXPLAINATION of all object types... ** read the output_comments ** https://code.sololearn.com/clbqf1lXQMoA/?ref=app
2nd Sep 2017, 2:40 PM
sayan chandra
sayan chandra - avatar
- 1
yep exactly.. good point
2nd Sep 2017, 1:51 PM
sayan chandra
sayan chandra - avatar