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 argparser flags 
Python :: python slice list 
Python :: create virtual environment python stack overflow 
Python :: confusion matrix 
Python :: python curses for windows 
Python :: python is instance 
Python :: rename colums dataframe pandas 
Python :: python if elif 
Python :: remove empty string from list python single line 
Python :: condition in python 
Python :: select random img in python using os.listdir 
Python :: python combinations 
Python :: not equal to python 
Python :: python list add to start 
Python :: django render example 
Python :: dataframe look at every second column 
Python :: pytorch dill model save 
Python :: Detect Word Then Send Message (discord.py) 
Python :: find index of element in array python 
Python :: matrix rotation in python 
Python :: check if 2 strings are equal python 
Python :: edit path variable using python 
Python :: condition python 
Python :: fillna spark dataframe 
Python :: sns.heatmap 
Python :: histogram for categorical data with plotly 
Python :: google sheet api python 
Python :: text generate gpt 2 huggingface 
Python :: how to run a command in command prompt using python 
Python :: python regions 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =