+ 2
Can any one help me please to clarify the exact differences between lists, sets, dictionaries, and tuples.
data structure types
5 Réponses
+ 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
+ 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()
+ 2
set u can also declair with { }
a = {1,2,3,2,5,2,6}
print (a)
{1,2,3,5,6}
+ 2
@@ Aseel najjer
run the code for DETAILED EXPLAINATION
of all object types...
** read the output_comments **
https://code.sololearn.com/clbqf1lXQMoA/?ref=app
- 1
yep exactly..
good point