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 :: what is variance in machine learning 
Python :: python get file size 
Python :: python print font size 
Python :: how to make a label in python 
Python :: add one element to tuple python 
Python :: python if in one line 
Python :: if elif and else in python 
Python :: //= python meaning 
Python :: when converting from dataframe to list delete nan values 
Python :: print column name and index dataframe 
Python :: Heroku gunicorn flask login is not working properly 
Python :: how to change title font size in plotly 
Python :: bar break matplotlib 
Python :: myshop flower notimplementederror 
Python :: Patch loop runner _run_once 
Python :: python string: escaping characters 
Python :: Python - Comment Parse String to List 
Python :: python goose 
Python :: how to increment datetime by custom months in python 
Python :: sarah 
Python :: python quickly goto line in file 
Python :: Update only values in python 
Python :: full_pickle 
Python :: seaborn regression jointplot for continuous variable .. 
Python :: python exception vs error 
Python :: integer to binary python 16 bit 
Python :: rename_and_convert_all_images_at_folder 
Python :: python integrated with activeX 
Python :: pandas read csv skip until expression found 
Python :: get the mean of all not nan values 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =