Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python tuple vs list

#tuples and lists are the same thing, but a tuple cannot be changed
tup = (1,'string',True)
lst = ['hiya',23545,None]
Comment

list vs tuple python

mylist : list = [] # <-- a list variable can be defined either as [] or <varname> : list
mytuple : tuple = () # <-- a tuple variable can be defined either as () or <varname> : tuple
Comment

list vs tuple

# compare the size
import sys
my_list = [0, 1, 2, "hello", True]
my_tuple = (0, 1, 2, "hello", True)
print(sys.getsizeof(my_list), "bytes")
print(sys.getsizeof(my_tuple), "bytes")

# compare the execution time of a list vs. tuple creation statement
import timeit
print(timeit.timeit(stmt="[0, 1, 2, 3, 4, 5]", number=1000000))
print(timeit.timeit(stmt="(0, 1, 2, 3, 4, 5)", number=1000000))
Comment

tuples vs list

# A tuple might contain data about a person (heterogeneous type mixture)
person_a = (name, age, occupation, address)

# A list might contain a list of people (homogeneous type mixture - all tuples!)
people = [person_a, person_b, person_c]
Comment

PREVIOUS NEXT
Code Example
Python :: python convert multidimensional array to one dimensional 
Python :: python rdp server 
Python :: python list 
Python :: WebDriverWait 
Python :: get dataframe column names 
Python :: python foreach list 
Python :: time 
Python :: how to make a use of list in python to make your own length function 
Python :: python variables in multiline string 
Python :: 3d array python numpy 
Python :: whatsapp online tracker python script 
Python :: run exe from python 
Python :: python get the last element from the list 
Python :: current date and time into timestamp 
Python :: how yo import python lib 
Python :: number of column in dataset pandas 
Python :: add a button pyqt5 
Python :: python custom sort 
Python :: how to execute bash commands in python script 
Python :: try except finally python 
Python :: seaborn and matplotlib Setting the xlim and ylim python 
Python :: python how to delete from dictionary a nan key 
Python :: how to use cos in python 
Python :: requests 
Python :: sum first 100 integers in python 
Python :: cumulative percentaile pandas 
Python :: np.random.RandomState 
Python :: python substring count 
Python :: who created python 
Python :: pytube 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =