Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6099935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:19:46+00:00 2026-05-23T13:19:46+00:00

I have a list in the given format: [[‘John’, ‘Smith’], [‘Linus’, ‘Torvalds’], [‘Bart’, ‘Simpson’]]

  • 0

I have a list in the given format:

[['John', 'Smith'], ['Linus', 'Torvalds'], ['Bart', 'Simpson']]

There are some elements like this in the list [‘Linus Torvalds’, ”] and I want to remove those. So why doesn’t the following code remove them?

for i in people:
    if(i[0] == '' or i[1] == ''):
        print people.pop(people.index(i))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:19:46+00:00Added an answer on May 23, 2026 at 1:19 pm

    You are changing the list while iterating over it and this is the source of your problems. An approach that works is

    people[:] = [p for p in people if p[0] != '' and p[1] != '']
    

    this way a new temporary list containing only the elements you want is built and then assigned to the original list object when the operation is complete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given a list of times (shop opening hours) but the format
I currently have a list of things to update in the given mysqli query:
I have a list of more than 15 thousand latitude and longitude coordinates. Given
I have a List<T> that I want to search not for a given item
I have been given a staff list which is supposed to be up to
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
I have a problem with how the List Sort method deals with sorting. Given
i have list of images and on mouse over there is option box shows
I have a list in the following format: [(index, count, color),(index+1,newcount,othercolor),...] And I want,
I have a huge list of URL's, in the format: http://www.example.com/dest/uk/bath/ http://www.example.com/dest/aus/sydney/ http://www.example.com/dest/aus/ http://www.example.com/dest/uk/

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.