In some programming languages, the last expression in a function is implicitly the value it returns. But in python, you have to have a return statement, or you get None.
def reverse_seq(n):
return sorted([i for i in range(1, n+1)], reverse=True)
Answer from kojiro on Stack OverflowZetCode
zetcode.com โบ python โบ reverse
Python reverse - reversing Python sequences
When we reverse items, we change their order. Note that reversing should not be confused with sorting in descending order. A Python list has a reverse function. The [::-1] slice operation to reverse a Python sequence. The reversed built-in function returns a reverse iterator.
Programiz
programiz.com โบ python-programming โบ methods โบ built-in โบ reversed
Python reversed()
string = 'Python' result = reversed(string) # convert the iterator to list and print it print(list(result)) # Output: ['n', 'o', 'h', 't', 'y', 'P'] ... The reversed() function takes a single argument. iterable - an iterable such as list, tuple, string, dictionary, etc.
Videos
23:52
How to use python to find the reverse of DNA sequences | ...
10:10
Reverse Complement using Basic Python - YouTube
05:32
How to make a reverse complement DNA sequence in python 3 5 - YouTube
02:43
Codewars (Python๐) | Reversed sequence | kyu8 - YouTube
03:20
Reverse a Sequence in python - YouTube
17:42
"Reverse a List in Python" Tutorial: Three Methods & How-to Demos ...
Top answer 1 of 3
2
In some programming languages, the last expression in a function is implicitly the value it returns. But in python, you have to have a return statement, or you get None.
def reverse_seq(n):
return sorted([i for i in range(1, n+1)], reverse=True)
2 of 3
2
You can use the range function like so:
def reverse_seq(n):
return range(n + 1, 1, -1)
- use
list(range(n + 1, 1, -1))if the output must be a list.
Scaler
scaler.com โบ home โบ topics โบ reversed in python | python reversed() function
Reversed in Python | Python reversed() Function - Scaler Topics
July 5, 2022 - The built-in reversed function in Python is used to reverse a sequence like a list, string, or tuple by creating a reverse iterator of the given sequence.
ThePythonGuru
thepythonguru.com โบ python-builtin-functions โบ reversed
Python reversed() function - ThePythonGuru.com
January 7, 2020 - The reversed() function allows us to process the items in a sequence in reverse order. It accepts a sequence and returns an iterator.Its syntax is asโฆ
GeeksforGeeks
geeksforgeeks.org โบ python โบ python-reverse-sequence-of-strictly-increasing-integers-in-a-list
Reverse sequence of strictly increasing integers in a list-Python - GeeksforGeeks
July 11, 2025 - Reverse and add the remaining block to res. Recursion splits the list into smaller subsequences by comparing each element with the previous one. When a strictly decreasing integer is encountered, it reverses the accumulated subsequence and recurses on the remaining list.
Real Python
realpython.com โบ reverse-string-python
Reverse Strings in Python: reversed(), Slicing, and More โ Real Python
July 31, 2023 - Passing None to the first two arguments of slice() tells the function that you want to rely on its internal default behavior, which is the same as a standard slicing with no values for start and stop. In other words, passing None to start and stop means that you want a slice from the left end to the right end of the underlying sequence. ... The second and arguably the most Pythonic approach to reversing strings is to use reversed() along with str.join().
The Teclado Blog
blog.teclado.com โบ python-quick-sequence-reversal
Quick Sequence Reversal in Python - The Teclado Blog
May 16, 2026 - Using slices we can get around these limitations, reversing any sequence we like before assigning it to a new variable. If we want to use the same variable name, of course we can, since Python allows us to bind names to new objects at will. friends = ["Rolf", "John", "Mary"] friends_reversed = friends[::-1] print(friends_reversed) # ['Mary', 'John', 'Rolf'] greet = "Hello, World!" print(greet[::-1]) # "!dlroW ,olleH"
W3Schools
w3schools.com โบ python โบ ref_func_reversed.asp
Python reversed() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ยท โฎ Built-in Functions ยท Reverse the sequence of a list, and print each item: alph = ["a", "b", "c", "d"] ralph = reversed(alph) for x in ralph: print(x) Try it Yourself ยป ยท
Python Morsels
pythonmorsels.com โบ looping-in-reverse
Looping in reverse - Python Morsels
May 27, 2025 - >>> colors = ["purple", "blue", "green", "pink", "red"] >>> for color in reversed(colors): ... print("I like", color) ... I like red I like pink I like green I like blue I like purple ยท I find reversed a lot more readable than Python's slicing syntax, but it's also more flexible. Python's slicing syntax only works on sequences, but reversed works on any reversible iterable!