Search code examples
pythonlistenumeration

How do I enumerate a list without parenthesis?


I have this python code, yet it adds parenthesis to the enumeration. I don't need the parenthesis, so how do I do this in python? All I need is just to enumerate the list. this is what it does is

num =[(0, '1'), (1, '7'), (2, '11'), (3, '13')

this is my code

num =['1', '7', '11', '13']
print (list(enumerate(num,0)))

I need this below, but I don't the code.

num = [1,'1', 2,'7',3,'11',4,'13'] 

Solution

  • Simply run a loop as below:

    num =['1', '7', '11', '13']
    final_list = list()
    for index, i in enumerate(num):
        final_list.extend((index, i))
    
    print(final_list)
    [0, '1', 1, '7', 2, '11', 3, '13']