Python Forum
Help with Logical error processing List of strings
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Logical error processing List of strings
#4
You can alter a list in place so long as you do it in reverse order:
list_of_users = ['josh', 'admin', 'cookie','jerry','jack']

def pop_item(lname):
    if len(lname):
        lname.pop(len(lname)-1)

while len(list_of_users):
    print(f"List length: {len(list_of_users)}, {list_of_users}")
    pop_item((list_of_users))

print(f"\nFinal length: {len(list_of_users)}")
results:
Output:
List length: 5, ['josh', 'admin', 'cookie', 'jerry', 'jack'] List length: 4, ['josh', 'admin', 'cookie', 'jerry'] List length: 3, ['josh', 'admin', 'cookie'] List length: 2, ['josh', 'admin'] List length: 1, ['josh'] Final length: 0
Reply


Messages In This Thread
RE: Help with Logical error processing List of strings - by Larz60+ - Nov-27-2022, 04:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read module/class from list of strings? popular_dog 1 421 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  Trying to understand strings and lists of strings Konstantin23 2 695 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  problem in using int() with a list of strings akbarza 4 644 Jul-19-2023, 06:46 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,702 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Convert each element of a list to a string for processing tester_V 6 5,166 Jun-16-2021, 02:11 AM
Last Post: tester_V
  Greedy algorithms on logical problems Opensourcehacker 0 1,507 Nov-22-2020, 05:12 PM
Last Post: Opensourcehacker
  Strange syntax error with f-strings Askic 6 4,074 Oct-16-2020, 10:40 AM
Last Post: Askic
  Unable to bit shift and logical OR bytes and ints? MysticLord 7 6,808 Sep-01-2020, 03:31 PM
Last Post: deanhystad
  Basic logical errors cpopescu 3 2,011 Jun-03-2020, 11:30 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020