You can do this in one line using itertools.groupby
:
import itertools
max(sum(1 for _ in l) for n, l in itertools.groupby(lst))
More Related Contents:
- Finding and counting the frequency of known pairs of words in multiple files [closed]
- Discord Py on_message bot=False blocked?
- Python script to ping linux server
- How to use global variables in Python?
- What does a b prefix before a python string mean?
- Why is dictionary ordering non-deterministic?
- Cannot install pygame in Pycharm
- How to run Spyder in virtual environment?
- What’s the difference between str.isdigit, isnumeric and isdecimal in python?
- Scrolling to element using webdriver?
- Conda command is not recognized on Windows 10
- How to prevent iterator getting exhausted?
- How to match any string from a list of strings in regular expressions in python?
- Pandas deleting row with df.drop doesn’t work
- TypeError: ‘range’ object does not support item assignment
- Is it bad practice to use a built-in function name as an attribute or method identifier?
- How can I get the domain name of my site within a Django template?
- How do I install theano in Anaconda ver. 2.1 Windows 64 bit for Python 3.4?
- Finding the nearest value and return the index of array in Python
- How to Open a file through python
- Error in Python script “Expected 2D array, got 1D array instead:”?
- multiprocessing vs multithreading vs asyncio
- Difference between AbstractUser and AbstractBaseUser in Django?
- Pip is not working for Python 3.10 on Ubuntu
- How to expire Django session in 5minutes?
- requests.get returns 403 while the same url works in browser
- Python: check if an object is a sequence
- Same name for classmethod and instancemethod
- How to calculate length of string in pixels for specific font and size?
- Why are str.count(”) and len(str) giving different outputs when used on an empty string?