Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to delete the middle element of a list in Python

2 Answers

0 votes
def deleteMiddleElement(st,  size,  current) :
    if ((len(st) == 0) or current == size) :
        return
    el = st[-1]
    
    st.pop()
    
    deleteMiddleElement(st, size, current + 1)
    
    if (current != int(size / 2)) :
        st.append(el)
    
    
st =  []
st.append('3')
st.append('5')
st.append('1')
st.append('m')
st.append('9')
st.append('2')
st.append('7')
        
deleteMiddleElement(st, len(st), 0)

print(st)




'''
run:

['3', '5', '1', '9', '2', '7']

'''

 



answered May 27, 2023 by avibootz
0 votes
st =  []
st.append('3')
st.append('5')
st.append('1')
st.append('m')
st.append('9')
st.append('2')
st.append('7')
        
del st[int(len(st) / 2)]

print(st)



'''
run:

['3', '5', '1', '9', '2', '7']

'''

 



answered May 27, 2023 by avibootz
...