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 :: gamma distribution python normalized 
Python :: map numpy array 
Python :: how to define a dictionary in python 
Python :: else if 
Python :: Remove an element from a Python list Using remove() method 
Python :: scrapy with selenium 
Python :: describe in python 
Python :: Python NumPy delete Function Example 
Python :: python number type 
Python :: python test framework 
Python :: what is print in python 
Python :: how to use the sleep function in python 
Python :: Python RegEx Subn – re.subn() 
Python :: fastest way to iterate dictionary python 
Python :: matplotlib units of scatter size 
Python :: python how to run code in ssh 
Python :: python list extend 
Python :: hash table data structure python 
Python :: looping nested dictionaries 
Python :: python inheritance 
Python :: search method in python 
Python :: pk django 
Python :: how to install python 
Python :: create anaconda env 
Python :: print column name and index python 
Python :: python click activator 
Python :: sum two linked lists if numbers are reversed in linked list 
Python :: Simple Kivy pong game 
Python :: python get num chars 
Python :: transpose([[1],[2],[3]]) 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =