Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert an element at the beginning of a list in Python?

Tags:

python

list

I have two lists and the first one is having additional data (102) when compared to the second one.

First List:

['102 1 1 v-csm CSM vCSM enabled active up D:042 H:20 M:14 S:58 5.4.4.4-68.REL']

Second List:

['2  1 v-csm  CSM  vCSM  enabled active up  D:331 H:12 M:20 S:33  5.4.4.4-68.REL']

I want to insert a string like "xyz" at the first position of the list so that using pandas data can be mapped to correct columns.

like image 609
Vishal Mishra Avatar asked Mar 08 '23 07:03

Vishal Mishra


1 Answers

Let's say that the second list is called array.

You can use array.insert(0, "xyz") or array = ["xyz"] + array to add "xyz" to the beginning of the second list.

like image 54
Adi219 Avatar answered Apr 02 '23 18:04

Adi219