Every number from 1,2,5,6,9,10... is divisible by 4 with remainder 1 or 2.

>>> ','.join(str(i) for i in xrange(100) if i % 4 in (1,2))
'1,2,5,6,9,10,13,14,...'
Answer from Aleksei astynax Pirogov on Stack Overflow
🌐
GitConnected
levelup.gitconnected.com › the-fastest-way-to-generate-a-sequence-in-python-a61da7f87852
The fastest way to generate a sequence in Python | by Astronomy not Astrology, hunty... | Level Up Coding
May 14, 2020 - The range() method generates an immutable object that is a sequence of numbers. The range() object can easily be converted into a Python list by enclosing it in the list method, for example, creating a list of values between 10 (start) and 0 (stop) decreasing in…
🌐
Real Python
realpython.com › python-sequences
Python Sequences: A Comprehensive Guide – Real Python
March 18, 2026 - This tutorial dives into Python sequences, which is one of the main categories of data types. You'll learn about the properties that make an object a sequence and how to create user-defined sequences.
🌐
Patrickwalls
patrickwalls.github.io › mathematicalpython › python › sequences
Sequences - Mathematical Python
It is very inefficient to create a sequence by manually typing the numbers. For example, simply typing out the numbers from 1 to 20 takes a long time! numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] print(numbers) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] Python has a beautiful syntax for creating lists called list comprehensions.
🌐
Python Morsels
pythonmorsels.com › make-a-sequence
How to make a sequence - Python Morsels
April 3, 2023 - Let's make a Fibonacci class which returns the first n numbers in the Fibonacci sequence. ... class Fibonacci: """Python sequence of the first N Fibonacci numbers (default 100).""" def __init__(self, n=100): self.n = n
🌐
TutorialsPoint
tutorialspoint.com › How-to-generate-sequences-in-Python
How to generate sequences in Python?
February 27, 2025 - Following are the various techniques to generate sequences in Python ? ... We can generate a sequence using a loop by starting with an empty sequence and appending values that meet a specified condition. In the following example, we have generated a sequence of all even numbers below 20 using ...
🌐
Quora
quora.com › How-do-you-create-a-sequence-in-Python
How to create a sequence in Python - Quora
Answer (1 of 4): In Python a list can be created like this: [code]my_list = [] [/code]or like this: [code]my_list = list() [/code]or with items of any data type: [code]my_list = ["apple", 1, 3.01] [/code]An sequence of number can be generated by the built-in function range(start, stop, step). ...
Find elsewhere
🌐
Howchoo
howchoo.com › python › python-range-function
Use the Python range() Function to Generate Sequences of ...
In Python, comprehensions are a useful construct that allows us to create new sequences in a very concise way.
🌐
Camdenreslink
code.camdenreslink.com › dev › 7-ways-to-create-sequences-in-python
7 Ways to Create Sequences in Python — Camden Reslink
December 5, 2018 - A generator function is a special function in Python, that can yield multiple values, instead of just a single return. Calling the generator creates an iterator, which can be iterated through with a for-loop. Generators are computed lazily. That means the next value isn’t calculated until you ask for it. This also means generators can represent infinite sequences...
🌐
Medium
medium.com › @nagasudhirpulla › create-sequences-with-range-function-in-python-6b98a0fbbf8b
Create sequences with range function in python | by Naga Sudhir | Medium
August 21, 2021 - Range is a python built-in sequence generator function through which we can generate sequences · These sequences can be used in for loops and many other situations ... start = optional input that specifies the number from which the sequence should start, default value is 0 · stop = input that specifies the number at which the sequence should end · step = optional input that specifies the incrementation of sequence. default value is 1 · # create a sequence from 0 to 4, i.e., 0,1,2,3,4 x = range(5)# create a sequence from 1 to 7, i.e., 1,2,3,4,5,6,7 x = range(1,8)# sequence from 2 to 12 with steps of 2, i.e., 2,4,6,8,10,12 x = range(2,13,2)
🌐
Copahost
copahost.com › home › python range: the complete range function guide
Python range: the complete range function guide - Copahost's
August 3, 2023 - Overall, understanding its advanced ... efficient data analysis and software development tools. The Python function range() generates a sequence of continuous numbers....
🌐
Reddit
reddit.com › r/learnpython › how to create a sequence of numbers from a string made of '+' and '-'?
r/learnpython on Reddit: How to create a sequence of numbers from a string made of '+' and '-'?
March 4, 2022 -

I have this very specific problem and not many ideas. I'm looking for some help to try to approach it. Here's the problem:

Given a sequence of no more than 8 '+' and '-' (strings), I need to form the smallest number possible following the rule: A '+' dictates that the next number is bigger than the current. A '-', that it's smaller. For example: if my string is '- - -', my number will be 4321, as all numbers are smaller than the one on their left, since the string is made only of '-'.

I forgot an important rule: The numbers have to be different! I can't have 1212 as a result, for example.

If I understand correctly, if I have a string with 'n' characters my number will be made of 'n+1' numbers. Now, I'm really out of ideas about how to implement a code for that. It's worth noting that I'm on a very basic level of learning python, the maximum i know is recursion (on a basic level, still). All I tried was using 'if/else' statements, but I'm not sure how to compare the numbers. Is using lists a good idea? And should I try recursion to go through the string?

Here's the code i have so far. Works only for the example i gave here.

def crypto(code:str):
    numbers = []
    # We start our list of numbers filling it with numbers equal to the length of the string. The idea is to decrease or increase these numbers accordingly with the srting
    for i in range(len(code)): 
        numbers.append(len(code)+1)

    # Here we decrease/increase. I'm not sure how to compare the numbers for cases like '-+-+', fro example.
    pos = 0
    for j in code:
        if j == '+':
            numbers[pos] += 1+pos
            pos += 1
        elif j == '-':
            numbers[pos] -= 1+pos
            pos += 1
    numbers.insert(0, len(codigo)+1)
    return print(numbers)


crypto('---')

🌐
DataCamp
campus.datacamp.com › courses › introduction-to-python-for-finance › arrays-in-python
Generating a sequence of numbers | Python
# Create and print company IDs company_ids = np.arange(____, ____, 1) print(company_ids) # Use array slicing to select specific company IDs company_ids_odd = ____(1, ____, ___) print(company_ids_odd)
🌐
CodeSpeedy
codespeedy.com › home › sequence generator in python
Sequence generator in Python - CodeSpeedy
February 9, 2020 - A generator is a type of function which generates the sequence in python. In mathematics, we usually represent the sequence by allowing duplicate members. In computer science, we generate a sequence by array, list, set, tuple, etc.
🌐
Vultr Docs
docs.vultr.com › python › built-in › range()
Python range() - Generate Number Sequence
September 27, 2024 - The range() function in Python is a versatile and essential tool for generating sequences of numbers, commonly used in loops and other iterative contexts. This function simplifies tasks involving the creation of number lists or the repetition of actions a specific number of times, making it ...
🌐
GeeksforGeeks
geeksforgeeks.org › python-create-list-of-numbers-with-given-range
Create List of Numbers with Given Range - Python - GeeksforGeeks
Python · r1 = 0 r2 = 10 li = list(range(r1,r2)) print(li) Output · [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Explanation: list(range(r1, r2)) creates a sequence of numbers from r1 to r2 using range() and converts it into a list li with list(). List ...
Published: May 1, 2025
🌐
Stack Overflow
stackoverflow.com › questions › 58333251 › creating-a-sequence-in-python-3
Creating a sequence in python 3 - Stack Overflow
It prints the sequence correctly. Now we need to find the period of the sequence. We can create another function for that.
🌐
Medium
medium.com › codex › custom-sequence-python-53ddcc37a1c7
Custom Sequence — Python
August 24, 2021 - We’ll use sequence protocol’s __getitem__ , __len__ to create our own sequence. We’ll also add other additives to make it potent.
🌐
The Teclado Blog
blog.teclado.com › creating-a-new-sequence-type-in-python-part-1
Creating a New Sequence Type in Python - Part 1
October 26, 2022 - In this post, we're going to be looking at Python's magic or "dunder" methods, and we're going to use these magic methods to start creating a brand new sequence type from scratch.
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python sequences
Python Sequences
March 27, 2025 - So the first element is s[0] and the second element is s[1]. If the sequence s has n items, the last item is s[n-1]. Python has the following built-in sequence types: lists, bytearrays, strings, tuples, range, and bytes.