Method 1: Using yield
The yield keyword enables a function to comeback where it left off when it is called again. This is the critical difference from a regular function. A regular function cannot comes back where it left off. The yield keyword helps a function to remember its state. The yield enables a function to suspend and resume while it turns in a value at the time of the suspension of the execution.
[['geeks', 'for', 'geeks', 'like', 'geeky'], ['nerdy', 'geek', 'love', 'questions', 'words'], ['life']]
Method 2: Using List comprehension
List comprehension is an elegant way to break a list in one line of code.
[[1, 2, 3, 4], [5, 6, 7, 8], ]
- Python | Group elements on break positions in list
- Python | Consecutive chunks Product
- Python | Convert String to N chunks tuple
- Find size of a list in Python
- Python | Subgroups of i'th index size in list
- Python | Size and element exponentiation of list
- Python | Size Range Combinations in list
- Python | Categorize the given list by string size
- Python | Sort list of lists by the size of sublists
- Python | Combinations of elements till size N in list
- Python | Increase list size by padding each element by N
- Python break statement
- break, continue and pass in Python
- NLP | Splitting and Merging Chunks
- Loops and Control Statements (continue, break and pass) in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.