Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python append to tuple list

apple = ('fruit', 'apple')
banana = ('fruit', 'banana')
dog = ('animal', 'dog')
# Make a list with these tuples
some_list = [apple, banana, dog]
# Check if it's actually a tuple list
print(some_list)
# Make a tuple to add to list
new_thing = ('animal', 'cat')
# Append it to the list
some_list.append(new_thing)
# Print it out to see if it worked
print(some_list)
Comment

how to append a tuple to a list

a_list = []
a_list.append((1, 2))       # Succeed! Tuple (1, 2) is appended to a_list
a_list.append(tuple(3, 4))  # Error message: ValueError: expecting Array or iterable
Comment

PREVIOUS NEXT
Code Example
Python :: subscriptable meaning in python 
Python :: how to create copy of all objects in list python 
Python :: python child class call parent method 
Python :: np array size 
Python :: python iteration 
Python :: create list of dictionaries from list of list python 
Python :: pd df merge 
Python :: eval in python 
Python :: python find minimum date in list 
Python :: python datetime to unix timestamp 
Python :: save set of numpy arrays to file py 
Python :: django set default value for model not form 
Python :: Send Fetch Request Django(Get Method) 
Python :: join function python 
Python :: Proj 4.9.0 must be installed. 
Python :: python dataframe show row 
Python :: drf model methods serializer 
Python :: value list in django 
Python :: image processing python 
Python :: queue peek python 
Python :: how to make every item compare the rest items of list in python 
Python :: time zone 
Python :: remove all consecutive duplicates from the string 
Python :: www.pd.date_range 
Python :: lower and upper case user input python 
Python :: python with braces 
Python :: python autoclick website 
Python :: mean absolute error in machine learning formula 
Python :: a function to create a null matrix in python 
Python :: python if in list 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =