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], ]
- Find size of a list in Python
- Python | Categorize the given list by string size
- Python | Subgroups of i'th index size in list
- Python | Increase list size by padding each element by N
- Python | Sort list of lists by the size of sublists
- Loops and Control Statements (continue, break and pass) in Python
- NLP | Splitting and Merging Chunks
- NLP | Expanding and Removing Chunks with RegEx
- Python | Convert list of string to list of list
- Python | Convert list of tuples to list of list
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Convert list of numerical string to list of Integers
- Python | Convert list of string into sorted list of integer
- Python | Find maximum length sub-list in a nested list
- Python | Pair and combine nested list to tuple list
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.