I am creating a list whose items are to be mapped by index number. I tried using the list.insert() method. But still it always adds the first element to 0th index and I want the first element at 1st index. For example:
somelist=[]
somelist.insert(1,"Jack")
somelist.insert(2,"Nick")
somelist.insert(3,"Daniel")
>>print(somelist[1])
Nick # not Jack
how can I do this in Python? where I can insert element only at given index and let the list start from index 1.
list.inset()is not a "inser at an index" instead it is "insert before(or at) the index",somelist.insert(1,"Jack")will insert at first at index0because no eleemnt exists before 1 indexsomelist.insert(0,None)0 index as Nonen - 1if yournis one based? Why are you really trying to shift the list elements?Noneat 0th index, better to changeprint(somelist[1])toprint(somelist[0])