Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

split list in half python

print(a_list)
length = len(a_list)
middle_index = length//2
first_half = a_list[:middle_index]
second_half = a_list[middle_index:]
print(first_half)
print(second_half)

>> [1, 2, 3, 4]
>> [1, 2]
>> [3, 4]
Comment

PREVIOUS NEXT
Code Example
Python :: multiple line input python 
Python :: how to check if a letter is lowercase in python 
Python :: get month name from datetime pandas 
Python :: python print for loop one line 
Python :: how to import flask restful using pip 
Python :: python remove background 
Python :: falsy values in python 
Python :: convert a number column into datetime pandas 
Python :: pip install django 
Python :: how to save a neural network pytorch 
Python :: how to underline text in tkinter 
Python :: python super init 
Python :: get int64 column pandas 
Python :: raising exceptions in python 
Python :: time.perf_counter 
Python :: getting the file path of a file object in python 
Python :: subprocess print logs 
Python :: python file handling 
Python :: datediff in seconds in pandas 
Python :: discord music queue python 
Python :: how to remove stop words in python 
Python :: python xml parser 
Python :: python date from string 
Python :: print textbox value in tkinter 
Python :: sklearn logistic regression get probability 
Python :: Count NaN values of an DataFrame 
Python :: python number and name of weekday 
Python :: renaming column in dataframe pandas 
Python :: lag function in pandas 
Python :: print subscript and superscript python 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =