Python Forum
The Empty List Blocks Recursion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The Empty List Blocks Recursion
#1
List = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
step = 4



def ResetCR (l, stp):
    K = []
    if stp != 0:
        for i in range(1, int(len(l)/stp)+1):
            K.append(l[i*stp - 1])
        l = [x for x in l if x not in K]
        stp = stp - 1
        return ResetCR(l,stp)
    if stp == 0:
        return K


F = ResetCR(List,step)

print (F)
I'm trying to change the order of a list. If the "K = []" is out side the function, it works. However, I'm wondering is there a way to keep the variable 'K' inside the function?
Reply


Messages In This Thread
The Empty List Blocks Recursion - by leoahum - Mar-05-2019, 03:13 PM
RE: The Empty List Blocks Recursion - by ichabod801 - Mar-05-2019, 03:34 PM
RE: The Empty List Blocks Recursion - by leoahum - Mar-05-2019, 03:53 PM
RE: The Empty List Blocks Recursion - by ichabod801 - Mar-05-2019, 04:11 PM
RE: The Empty List Blocks Recursion - by leoahum - Mar-05-2019, 04:36 PM
RE: The Empty List Blocks Recursion - by ichabod801 - Mar-05-2019, 06:32 PM
RE: The Empty List Blocks Recursion - by leoahum - Mar-05-2019, 06:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  what to return for an empty list Skaperen 2 262 May-24-2024, 05:17 PM
Last Post: Skaperen
  Code with empty list not executing adeana 9 3,914 Dec-11-2023, 08:27 AM
Last Post: buran
  RSA Cipher with blocks Paragoon2 0 573 Nov-26-2023, 04:35 PM
Last Post: Paragoon2
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 2,082 Dec-12-2022, 08:22 PM
Last Post: jh67
  set.difference of two list gives empty result wardancer84 4 1,611 Jun-14-2022, 01:36 PM
Last Post: wardancer84
  displaying empty list vlearner 5 1,777 Jan-19-2022, 09:12 AM
Last Post: perfringo
  Remove empty keys in a python list python_student 7 3,249 Jan-12-2022, 10:23 PM
Last Post: python_student
  Browse and build a list of folder paths using recursion Ultrainstinct_5 8 5,219 Apr-24-2021, 01:41 PM
Last Post: Ultrainstinct_5
  Am I a retard - else and finally blocks in a try statement RubenF85 6 2,746 Jan-12-2021, 05:56 PM
Last Post: bowlofred
  What is the value after JOINING an empty list? JaneTan 2 5,423 Jan-04-2021, 06:25 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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