Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

manipulate list using slice assignment

# Use Slice Assignment 
l1 = [10,20,30,40,50,60,70,80,90]

#Replace
l1[1:3] = [21,31]
l1
#[10, 21, 31, 40, 50, 60, 70, 80, 90]
#Delete
l1[1:3] = []
l1
#[10, 40, 50, 60, 70, 80, 90]
#Add
l1[1:1] = [10,20,30]
l1
#[10, 10, 20, 30, 40, 50, 60, 70, 80, 90]
Comment

PREVIOUS NEXT
Code Example
Python :: How to avoit print() to go to newline each time 
Python :: # find the n smallest and greatest numbers in list 
Python :: python exe restart 
Python :: for _ in range python 
Python :: # filter a list 
Python :: matplotlib get colorwheel 
Python :: make seaborn plot larger to fit legend 
Python :: load shapefile fiona multiline intersection 
Python :: menjumlahkan elemen tertentu pada list dalam dictionary python 
Python :: python online compiler with libraries 
Python :: python string formatting - string truncating with format() 
Python :: looping emails using a database with python code 
Python :: Code Example of Checking if a variable is None using is operator 
Python :: Errors while using os.makedirs() method 
Python :: how to decide that the input must be a integer less than 5 in python 
Python :: merge sort dictionary python 
Python :: python combine images horizontally next to each other 
Python :: vorticity 
Python :: convert a float array to an integer 
Python :: pandas iloc stack overflow 
Python :: Python NumPy ndarray.T Example 
Python :: python text file contains 
Python :: Python NumPy asarray_chkfinite Function Syntax 
Python :: tensorflow configure multiple gpu 
Python :: max index tuple 
Python :: NumPy resize Example out of bound values [appending zeros] 
Python :: sourcetrail index library python 
Python :: main code for bpsk scheme 
Python :: pandas dataframe limit rows by col value 
Python :: list python !g 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =