Data Handling With Lists
My problem is related to handling data from multiple lists. Consider I have two lists.
a = ['a','b','c'] b = ['d','e','f','g','h']
I want to create a nested list which will add all the elements of one list (list a) into another (list b) without altering any elements in the second list (list b).
So, the output would look like:
output = [['a','d','e','f','g','h'], ['b','d','e','f','g','h'],['c','d','e','f','g','h']]
Can anyone say an efficient way to achieve this output. Thank you in advance.
This list comprehension seems to do the job:
output = [list(item) + b for item in a]
- → How to configure JSON for graphql query?
- → Google couldn't fetch my sitemap.xml file
- → A lot of socket endpoints in python?
- → Historical price per minute between two timestamps for a cryptocurrency
- → How to get a value from a list of dictionaries - Python 3.7.1
- → What is the optimal way to parse these strings in Python?
- → Short Order on Binance futures testnet resulting in APIError (ReduceOnly Order is Rejected)
- → values subtracted while iterating through list has random miscalculations
- → Foreign key query error in case of custom uint64 field which was used as a primary key
- → Grouping all tests Python
- → Using #!python2 not working to run under Python 2
- → Storing last 3 scores and deleting older scores and calculating average?
- → Checking if input is in a list of numbers in python