Python Forum
Creating a list from a sequence without while-loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a list from a sequence without while-loop
#1
Suppose I have a sequence [x][/n]. I want to create a list of [x][/n] for all n>0 as long as [x][/n] is greater than a given constant. I'm confused on how to go about this. I have defined the sequence as a function, but simply don't understand how one would solve this with a for-loop for example. I keep trying to find a way to create a range(0, infinity), but this gets very convoluted. Any help would be appreciated.
Reply
#2
see itertools: https://docs.python.org/3.7/library/itertools.html
Reply
#3
If you already have a sequence, and you want a subset of that sequence, you wouldn't use a while loop or for i in range(Infinity): anyway. You'd just iterate over the sequence.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating guest list manager nickster11 1 2,843 Feb-08-2021, 02:44 PM
Last Post: deanhystad
  Need help on sequence and loop homework vzsnv 3 2,192 Nov-04-2020, 05:02 PM
Last Post: perfringo
  Help with while loop creating an infinite loop. FWendeburg 3 3,027 Jan-30-2019, 08:28 PM
Last Post: FWendeburg
  EASY- creating a for loop with a list rico 2 2,665 Nov-30-2018, 03:53 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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