I have a list of multiple integers and strings ['-200', ' 0', ' 200', ' 400', ' green', '0', '0', '200', '400', ' yellow', '200', '0', '200', '400', ' red'] I'm having difficulty separating the list every 5 elements and creating a new list with just 5 elements inside. However, i don't want 3 different lists, i just want one that changes everytime a new 5 elements goes through.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You could do it in a single sentence like
Then the output should be :
You want something like:
Output:
What do you mean by a "new" 5 elements?
If you want to append to this list you can do:
I feel that you will have to create 1 new list, but if I understand correctly, you want a nested list with 5 elements in each sublist.
You could try the following:
This will step through your first list, 'l', and group 5 elements together into a sublist in new. Output:
Hope this helps