range(1, n+1)
is not considered duplication, but I can see that this might become a hassle if you were going to change 1
to another number.
This removes the duplication using a generator:
for _ in (number+1 for number in range(5)): print(_)
Related Posts:
- Python – TypeError: ‘int’ object is not iterable
- Why there is no do while loop in python
- Python – TypeError: ‘int’ object is not iterable
- Accessing the index in ‘for’ loops?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Pythonic way to combine FOR loop and IF statement
- Subplot for seaborn boxplot
- Exit while loop in Python
- Loop backwards using indices in Python?
- Why does using from __future__ import print_function breaks Python2-style print?
- Breaking out of nested loops
- Is there a “do … until” in Python?
- Iterating over a 2 dimensional python list [duplicate]
- Infinite for loops possible in Python?
- python: restarting a loop
- Python loop counter in a for loop
- Get a Try statement to loop around until correct value obtained
- Python: Continuing to next iteration in outer loop
- Import Error: No module named numpy
- bash: pip: command not found
- Function for Factorial in Python
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Writing a pandas DataFrame to CSV file
- Purpose of “%matplotlib inline”
- How do I update Anaconda?
- TypeError: ‘str’ object is not callable (Python)
- Dijkstra’s algorithm in python
- How to create a GUID/UUID in Python
- OSError: [WinError 193] %1 is not a valid Win32 application
- How to download a file over HTTP?
- Can’t fix “zipimport.ZipImportError: can’t decompress data; zlib not available” when I type in “python3.6 get-pip.py”
- Arrays used as indices must be of integer (or boolean) type
- Are static class variables possible in Python?
- Why am I getting “LinAlgError: Singular matrix” from grangercausalitytests?
- ‘method’ object is not subscriptable. Don’t know what’s wrong
- How do I copy a file in Python?
- EOFError: Ran out of input
- Get Color Palettes from ColorHunt.co in Python
- How do you read from stdin?
- Union of two lists in Python
- Type error: cannot convert the series to
- Reading a binary file with python
- How to determine a Python variable’s type?
- Could not find a version that satisfies the requirement
- Removing Conda environment
- Cannot convert list to array: ValueError: only one element tensors can be converted to Python scalars
- How do I plot only a table in Matplotlib?
- Change column type in pandas
- Start with pyglet or pygame?
- Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given
- Python error load JSON code of google API
- How to convert IPython notebooks to PDF and HTML?
- ‘Jupyter’ is not recognized as an internal or external command
- How to print spaces in Python?
- installing urllib in Python3.6
- What is sys.maxint in Python 3?
- How do you get the magnitude of a vector in Numpy?
- Finding all possible permutations of a given string in python
- Difference between scikit-learn and sklearn
- How can I create a text input box with Pygame?
- How can I print variable and string on same line in Python?
- SettingWithCopyWarning even when using .loc[row_indexer,col_indexer] = value
- Append a tuple to a list – what’s the difference between two ways?
- No module named Image
- How to fix “TypeError: len() of unsized object”
- ValueError: Unknown projection ‘3d’ (once again)
- Difference between len() and .__len__()?
- Good ways to “expand” a numpy ndarray?
- Python data structure sort list alphabetically
- TypeError: ‘numpy.float64’ object does not support item assignment
- TypeError: unsupported format string passed to list.__format__
- Getting “socket.error: [Errno 61] Connection refused” python paramiko
- python setup.py uninstall
- ImportError: No module named cv2
- Create numpy matrix filled with NaNs
- python pandas remove duplicate columns
- What is the difference between __str__ and __repr__?
- How often does python flush to a file?
- How to open every file in a folder
- Python iteration over non-sequence
- How do I convert a string to a double in Python?
- _csv.Error: field larger than field limit (131072)
- How do I rotate an image around its center using Pygame?
- How can I copy a Python string?
- Issue with virtualenv – cannot activate
- Can I set max_retries for requests.request?
- How to completely uninstall python 2.7.13 on Ubuntu 16.04
- Calculate weighted average using a pandas/dataframe
- Telling Python to save a .txt file to a certain directory on Windows and Mac
- Spell Checker for Python
- TypeError: coercing to Unicode: need string or buffer, int found
- How to get POSTed JSON in Flask?
- How to fix SSL issue SSL_CTX_use_certificate : ca md too weak on Python Zeep
- Paramiko’s SSHClient with SFTP
- Package libffi was not found in the pkg-config search path REDHAT6.5
- Line is too long. Django PEP8
- TypeError: zip argument #2 must support iteration
- CS231n: How to calculate gradient for Softmax loss function?
- How to create a new database using SQLAlchemy?