Created
December 20, 2018 04:49
-
-
Save k7faq/d7ad631c0dc5c76eeb4023d3b0be3801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Mixed list of array(list) and integer | |
| mixed=[ 'a', [1],2,[3], ['B'] ] | |
| # function to extract value(s) from a list which may contain lists of integers | |
| def flattenMixedList( mixed ): | |
| for item in mixed: | |
| if isinstance(item, list): | |
| for thisItem in item: yield thisItem | |
| else: | |
| yield item | |
| # call function to flatten list | |
| print( list( flattenMixedList( mixed ) ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment