简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM