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 | Subgroups of i'th index size in list
- Python | Categorize the given list by string size
- Python | Sort list of lists by the size of sublists
- Python | Increase list size by padding each element by N
- Python | Combinations of elements till size N in list
- 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 tuples to list of list
- Python | Convert list of string to list of list
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Pair and combine nested list to tuple list
- Python | Replace elements in second list with index of same element in first list
- Python | Convert list of numerical string to list of Integers
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.