I have two lists that I will later use do determine on how many pages of a document I'm looking at. The first list (l_name) contains the name of the document. The second list (l_depth) contains the number of pages I will look at, always starting from the first one.
The original lists look like this:
l_name = ['Doc_1', 'Doc_2', 'Doc_3']
l_depth = [1, 3, 2]
As I want to use a for loop to indicate each page I will be looking at
for d,p in zip(l_doc, l_page):
open doc(d) on page(p)
do stuff
I need the new lists to look like this:
l_doc = ['Doc_1', 'Doc_2', 'Doc_2', 'Doc_2', 'Doc_3', 'Doc_3']
l_page = [1, 1, 2, 3, 1, 2]
How can I multiply the names (l_name --> l_doc) based on the required depth and provide the range (l_depth --> l_page) also based on the depth?
You can get your list with comprehension:
[k for i, j in zip(l_name, l_depth) for k in [i]*j]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With