Print 'x' amount of items 'y' times?












2















So, I'm trying to have an item for list1 printed once, then the first element of item2 dictates how many items from list 3 are printed, then the next loop around, it starts where it left off. Then repeat until I run out of items from list1.. I think I have all the lists formatted right because list1 is a list of strings, list2 is a list of integers and list3 is another list of strings



prevval = 0
for i in list1:
print(i)
for j in list2:
val = j
print(list3[prevval:val])
prevval = val


it prints out the first x amount of items from list 3, a total of 8 times (which is how many elements are in list 2)



Sample:



list1 = ["test","please"]
list2 = [2, 4, 6]
list3 = ["hard", "to", "come", "up","with","values"]


it will print:



test
hard to
hard to
hard to
hard to come


expected would be:



test
hard to
please
come up with values


etc










share|improve this question

























  • list, list, list3... what are they?

    – U9-Forward
    Nov 21 '18 at 4:15











  • So what's the issue?

    – BallpointBen
    Nov 21 '18 at 4:15






  • 1





    List1 is a list of strings, list2 is a list of integers, list3 is a list of strings

    – SoloTriesToLearn
    Nov 21 '18 at 4:16






  • 2





    Do you want val += j instead of val = j?

    – NotAnAmbiTurner
    Nov 21 '18 at 4:17






  • 2





    where does that 1 come from in your desired output?

    – Kevin Fang
    Nov 21 '18 at 4:26


















2















So, I'm trying to have an item for list1 printed once, then the first element of item2 dictates how many items from list 3 are printed, then the next loop around, it starts where it left off. Then repeat until I run out of items from list1.. I think I have all the lists formatted right because list1 is a list of strings, list2 is a list of integers and list3 is another list of strings



prevval = 0
for i in list1:
print(i)
for j in list2:
val = j
print(list3[prevval:val])
prevval = val


it prints out the first x amount of items from list 3, a total of 8 times (which is how many elements are in list 2)



Sample:



list1 = ["test","please"]
list2 = [2, 4, 6]
list3 = ["hard", "to", "come", "up","with","values"]


it will print:



test
hard to
hard to
hard to
hard to come


expected would be:



test
hard to
please
come up with values


etc










share|improve this question

























  • list, list, list3... what are they?

    – U9-Forward
    Nov 21 '18 at 4:15











  • So what's the issue?

    – BallpointBen
    Nov 21 '18 at 4:15






  • 1





    List1 is a list of strings, list2 is a list of integers, list3 is a list of strings

    – SoloTriesToLearn
    Nov 21 '18 at 4:16






  • 2





    Do you want val += j instead of val = j?

    – NotAnAmbiTurner
    Nov 21 '18 at 4:17






  • 2





    where does that 1 come from in your desired output?

    – Kevin Fang
    Nov 21 '18 at 4:26
















2












2








2








So, I'm trying to have an item for list1 printed once, then the first element of item2 dictates how many items from list 3 are printed, then the next loop around, it starts where it left off. Then repeat until I run out of items from list1.. I think I have all the lists formatted right because list1 is a list of strings, list2 is a list of integers and list3 is another list of strings



prevval = 0
for i in list1:
print(i)
for j in list2:
val = j
print(list3[prevval:val])
prevval = val


it prints out the first x amount of items from list 3, a total of 8 times (which is how many elements are in list 2)



Sample:



list1 = ["test","please"]
list2 = [2, 4, 6]
list3 = ["hard", "to", "come", "up","with","values"]


it will print:



test
hard to
hard to
hard to
hard to come


expected would be:



test
hard to
please
come up with values


etc










share|improve this question
















So, I'm trying to have an item for list1 printed once, then the first element of item2 dictates how many items from list 3 are printed, then the next loop around, it starts where it left off. Then repeat until I run out of items from list1.. I think I have all the lists formatted right because list1 is a list of strings, list2 is a list of integers and list3 is another list of strings



prevval = 0
for i in list1:
print(i)
for j in list2:
val = j
print(list3[prevval:val])
prevval = val


it prints out the first x amount of items from list 3, a total of 8 times (which is how many elements are in list 2)



Sample:



list1 = ["test","please"]
list2 = [2, 4, 6]
list3 = ["hard", "to", "come", "up","with","values"]


it will print:



test
hard to
hard to
hard to
hard to come


expected would be:



test
hard to
please
come up with values


etc







python list






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 4:29







SoloTriesToLearn

















asked Nov 21 '18 at 4:12









SoloTriesToLearnSoloTriesToLearn

546




546













  • list, list, list3... what are they?

    – U9-Forward
    Nov 21 '18 at 4:15











  • So what's the issue?

    – BallpointBen
    Nov 21 '18 at 4:15






  • 1





    List1 is a list of strings, list2 is a list of integers, list3 is a list of strings

    – SoloTriesToLearn
    Nov 21 '18 at 4:16






  • 2





    Do you want val += j instead of val = j?

    – NotAnAmbiTurner
    Nov 21 '18 at 4:17






  • 2





    where does that 1 come from in your desired output?

    – Kevin Fang
    Nov 21 '18 at 4:26





















  • list, list, list3... what are they?

    – U9-Forward
    Nov 21 '18 at 4:15











  • So what's the issue?

    – BallpointBen
    Nov 21 '18 at 4:15






  • 1





    List1 is a list of strings, list2 is a list of integers, list3 is a list of strings

    – SoloTriesToLearn
    Nov 21 '18 at 4:16






  • 2





    Do you want val += j instead of val = j?

    – NotAnAmbiTurner
    Nov 21 '18 at 4:17






  • 2





    where does that 1 come from in your desired output?

    – Kevin Fang
    Nov 21 '18 at 4:26



















list, list, list3... what are they?

– U9-Forward
Nov 21 '18 at 4:15





list, list, list3... what are they?

– U9-Forward
Nov 21 '18 at 4:15













So what's the issue?

– BallpointBen
Nov 21 '18 at 4:15





So what's the issue?

– BallpointBen
Nov 21 '18 at 4:15




1




1





List1 is a list of strings, list2 is a list of integers, list3 is a list of strings

– SoloTriesToLearn
Nov 21 '18 at 4:16





List1 is a list of strings, list2 is a list of integers, list3 is a list of strings

– SoloTriesToLearn
Nov 21 '18 at 4:16




2




2





Do you want val += j instead of val = j?

– NotAnAmbiTurner
Nov 21 '18 at 4:17





Do you want val += j instead of val = j?

– NotAnAmbiTurner
Nov 21 '18 at 4:17




2




2





where does that 1 come from in your desired output?

– Kevin Fang
Nov 21 '18 at 4:26







where does that 1 come from in your desired output?

– Kevin Fang
Nov 21 '18 at 4:26














6 Answers
6






active

oldest

votes


















2














For each word in list1 you want to print a slice of list3 determined by the corresponding value in list2. You can do that by zipping list1 and list2 and computing the appropriate slices:



list1 = ["test","please"]
list2 = [2, 4, 6]
list3 = ["hard", "to", "come", "up","with","values"]

prevval = 0
for w1, i in zip(list1, list2):
print(w1)
if prevval < len(list3):
print(list3[prevval:prevval + i])
prevval += i


Output



test
['hard', 'to']
please
['come', 'up', 'with', 'values']


If you want to format the lists as a string, you can use join:



' '.join(print(list3[prevval:prevval + i]))





share|improve this answer
























  • Might you not get an IndexError if prevval + i >= len(list3)? (eg. a short list3)

    – NotAnAmbiTurner
    Nov 21 '18 at 4:41













  • @NotAnAmbiTurner No. You'll just get a slice till the end of the list. From the doc "However, out of range slice indexes are handled gracefully when used for slicing" (this was for strings but applies to lists too: docs.python.org/3/tutorial/introduction.html#strings)

    – slider
    Nov 21 '18 at 4:44





















0














This will destroy list3:



list1 = ["test","please"]
list2 = [2, 4, 6]
list3 = ["hard", "to", "come", "up","with","values"]

l1_idx = 0
l2_idx = 0

while l3_idx < len(list3):
print(list1[l1_idx])
l1_idx += 1
outarr =
for x in range(list2[l2_idx]):
try:
outarr.append(list3.pop(0))
except IndexError:
break
print(" ".join(outarr))
l2_idx += 1





share|improve this answer































    0














    The shortest one here:



    prevval=0
    for x,y in zip(list1,list2):
    print(x)
    print(' '.join(list3[prevval:prevval+y]))
    prevval+=y


    The output is:



    test
    hard to
    please
    come up with values


    zip them and iterate over, add prevval as usual, and remove the inner loop, that's all the changes, note that it makes it shorter (by far).






    share|improve this answer
























    • The problem with omitting the if statement is that if list3 = ["hard"] it'll print an empty list (or blank line in this case) which I'm not sure is desirable.

      – slider
      Nov 21 '18 at 4:51





















    0














    #!/bin/python

    list1 = ["test","please"]
    list2 = [2, 4, 6]
    list3 = ["hard", "to", "come", "up","with","values"]

    for i in list1:
    print(i)
    s =
    for j in range(list2.pop(0)):
    s.append(list3.pop(0))
    print(" ".join(s))


    Output:



    test
    hard to
    please
    come up with values





    share|improve this answer































      0














      list1 = ['test', 'please', 'this', 'works']
      list2 = [2,4,6]
      list3 = tmp = ['hard', 'to', 'come', 'up', 'with', 'values', 'because', 'it', 'is', 'simple', 'with', 'python']
      for index, item in enumerate(list1):
      try:
      print(tmp[:list2[index]])
      tmp = tmp[list2[index]:]
      except:
      break





      share|improve this answer































        0














        prevval = 0

        val=0

        for i in list1:

        print(i)

        val=list2[val]

        print(list3[prevval:val])

        prevval = val





        share|improve this answer


























        • Code only answers are discouraged. Always add a bit of explanation. Beyond that: make sure to nicely format indent all of your input, instead of just dumping text on others.

          – GhostCat
          Nov 21 '18 at 8:41











        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405155%2fprint-x-amount-of-items-y-times%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        For each word in list1 you want to print a slice of list3 determined by the corresponding value in list2. You can do that by zipping list1 and list2 and computing the appropriate slices:



        list1 = ["test","please"]
        list2 = [2, 4, 6]
        list3 = ["hard", "to", "come", "up","with","values"]

        prevval = 0
        for w1, i in zip(list1, list2):
        print(w1)
        if prevval < len(list3):
        print(list3[prevval:prevval + i])
        prevval += i


        Output



        test
        ['hard', 'to']
        please
        ['come', 'up', 'with', 'values']


        If you want to format the lists as a string, you can use join:



        ' '.join(print(list3[prevval:prevval + i]))





        share|improve this answer
























        • Might you not get an IndexError if prevval + i >= len(list3)? (eg. a short list3)

          – NotAnAmbiTurner
          Nov 21 '18 at 4:41













        • @NotAnAmbiTurner No. You'll just get a slice till the end of the list. From the doc "However, out of range slice indexes are handled gracefully when used for slicing" (this was for strings but applies to lists too: docs.python.org/3/tutorial/introduction.html#strings)

          – slider
          Nov 21 '18 at 4:44


















        2














        For each word in list1 you want to print a slice of list3 determined by the corresponding value in list2. You can do that by zipping list1 and list2 and computing the appropriate slices:



        list1 = ["test","please"]
        list2 = [2, 4, 6]
        list3 = ["hard", "to", "come", "up","with","values"]

        prevval = 0
        for w1, i in zip(list1, list2):
        print(w1)
        if prevval < len(list3):
        print(list3[prevval:prevval + i])
        prevval += i


        Output



        test
        ['hard', 'to']
        please
        ['come', 'up', 'with', 'values']


        If you want to format the lists as a string, you can use join:



        ' '.join(print(list3[prevval:prevval + i]))





        share|improve this answer
























        • Might you not get an IndexError if prevval + i >= len(list3)? (eg. a short list3)

          – NotAnAmbiTurner
          Nov 21 '18 at 4:41













        • @NotAnAmbiTurner No. You'll just get a slice till the end of the list. From the doc "However, out of range slice indexes are handled gracefully when used for slicing" (this was for strings but applies to lists too: docs.python.org/3/tutorial/introduction.html#strings)

          – slider
          Nov 21 '18 at 4:44
















        2












        2








        2







        For each word in list1 you want to print a slice of list3 determined by the corresponding value in list2. You can do that by zipping list1 and list2 and computing the appropriate slices:



        list1 = ["test","please"]
        list2 = [2, 4, 6]
        list3 = ["hard", "to", "come", "up","with","values"]

        prevval = 0
        for w1, i in zip(list1, list2):
        print(w1)
        if prevval < len(list3):
        print(list3[prevval:prevval + i])
        prevval += i


        Output



        test
        ['hard', 'to']
        please
        ['come', 'up', 'with', 'values']


        If you want to format the lists as a string, you can use join:



        ' '.join(print(list3[prevval:prevval + i]))





        share|improve this answer













        For each word in list1 you want to print a slice of list3 determined by the corresponding value in list2. You can do that by zipping list1 and list2 and computing the appropriate slices:



        list1 = ["test","please"]
        list2 = [2, 4, 6]
        list3 = ["hard", "to", "come", "up","with","values"]

        prevval = 0
        for w1, i in zip(list1, list2):
        print(w1)
        if prevval < len(list3):
        print(list3[prevval:prevval + i])
        prevval += i


        Output



        test
        ['hard', 'to']
        please
        ['come', 'up', 'with', 'values']


        If you want to format the lists as a string, you can use join:



        ' '.join(print(list3[prevval:prevval + i]))






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 4:34









        sliderslider

        8,49811331




        8,49811331













        • Might you not get an IndexError if prevval + i >= len(list3)? (eg. a short list3)

          – NotAnAmbiTurner
          Nov 21 '18 at 4:41













        • @NotAnAmbiTurner No. You'll just get a slice till the end of the list. From the doc "However, out of range slice indexes are handled gracefully when used for slicing" (this was for strings but applies to lists too: docs.python.org/3/tutorial/introduction.html#strings)

          – slider
          Nov 21 '18 at 4:44





















        • Might you not get an IndexError if prevval + i >= len(list3)? (eg. a short list3)

          – NotAnAmbiTurner
          Nov 21 '18 at 4:41













        • @NotAnAmbiTurner No. You'll just get a slice till the end of the list. From the doc "However, out of range slice indexes are handled gracefully when used for slicing" (this was for strings but applies to lists too: docs.python.org/3/tutorial/introduction.html#strings)

          – slider
          Nov 21 '18 at 4:44



















        Might you not get an IndexError if prevval + i >= len(list3)? (eg. a short list3)

        – NotAnAmbiTurner
        Nov 21 '18 at 4:41







        Might you not get an IndexError if prevval + i >= len(list3)? (eg. a short list3)

        – NotAnAmbiTurner
        Nov 21 '18 at 4:41















        @NotAnAmbiTurner No. You'll just get a slice till the end of the list. From the doc "However, out of range slice indexes are handled gracefully when used for slicing" (this was for strings but applies to lists too: docs.python.org/3/tutorial/introduction.html#strings)

        – slider
        Nov 21 '18 at 4:44







        @NotAnAmbiTurner No. You'll just get a slice till the end of the list. From the doc "However, out of range slice indexes are handled gracefully when used for slicing" (this was for strings but applies to lists too: docs.python.org/3/tutorial/introduction.html#strings)

        – slider
        Nov 21 '18 at 4:44















        0














        This will destroy list3:



        list1 = ["test","please"]
        list2 = [2, 4, 6]
        list3 = ["hard", "to", "come", "up","with","values"]

        l1_idx = 0
        l2_idx = 0

        while l3_idx < len(list3):
        print(list1[l1_idx])
        l1_idx += 1
        outarr =
        for x in range(list2[l2_idx]):
        try:
        outarr.append(list3.pop(0))
        except IndexError:
        break
        print(" ".join(outarr))
        l2_idx += 1





        share|improve this answer




























          0














          This will destroy list3:



          list1 = ["test","please"]
          list2 = [2, 4, 6]
          list3 = ["hard", "to", "come", "up","with","values"]

          l1_idx = 0
          l2_idx = 0

          while l3_idx < len(list3):
          print(list1[l1_idx])
          l1_idx += 1
          outarr =
          for x in range(list2[l2_idx]):
          try:
          outarr.append(list3.pop(0))
          except IndexError:
          break
          print(" ".join(outarr))
          l2_idx += 1





          share|improve this answer


























            0












            0








            0







            This will destroy list3:



            list1 = ["test","please"]
            list2 = [2, 4, 6]
            list3 = ["hard", "to", "come", "up","with","values"]

            l1_idx = 0
            l2_idx = 0

            while l3_idx < len(list3):
            print(list1[l1_idx])
            l1_idx += 1
            outarr =
            for x in range(list2[l2_idx]):
            try:
            outarr.append(list3.pop(0))
            except IndexError:
            break
            print(" ".join(outarr))
            l2_idx += 1





            share|improve this answer













            This will destroy list3:



            list1 = ["test","please"]
            list2 = [2, 4, 6]
            list3 = ["hard", "to", "come", "up","with","values"]

            l1_idx = 0
            l2_idx = 0

            while l3_idx < len(list3):
            print(list1[l1_idx])
            l1_idx += 1
            outarr =
            for x in range(list2[l2_idx]):
            try:
            outarr.append(list3.pop(0))
            except IndexError:
            break
            print(" ".join(outarr))
            l2_idx += 1






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 21 '18 at 4:38









            NotAnAmbiTurnerNotAnAmbiTurner

            768522




            768522























                0














                The shortest one here:



                prevval=0
                for x,y in zip(list1,list2):
                print(x)
                print(' '.join(list3[prevval:prevval+y]))
                prevval+=y


                The output is:



                test
                hard to
                please
                come up with values


                zip them and iterate over, add prevval as usual, and remove the inner loop, that's all the changes, note that it makes it shorter (by far).






                share|improve this answer
























                • The problem with omitting the if statement is that if list3 = ["hard"] it'll print an empty list (or blank line in this case) which I'm not sure is desirable.

                  – slider
                  Nov 21 '18 at 4:51


















                0














                The shortest one here:



                prevval=0
                for x,y in zip(list1,list2):
                print(x)
                print(' '.join(list3[prevval:prevval+y]))
                prevval+=y


                The output is:



                test
                hard to
                please
                come up with values


                zip them and iterate over, add prevval as usual, and remove the inner loop, that's all the changes, note that it makes it shorter (by far).






                share|improve this answer
























                • The problem with omitting the if statement is that if list3 = ["hard"] it'll print an empty list (or blank line in this case) which I'm not sure is desirable.

                  – slider
                  Nov 21 '18 at 4:51
















                0












                0








                0







                The shortest one here:



                prevval=0
                for x,y in zip(list1,list2):
                print(x)
                print(' '.join(list3[prevval:prevval+y]))
                prevval+=y


                The output is:



                test
                hard to
                please
                come up with values


                zip them and iterate over, add prevval as usual, and remove the inner loop, that's all the changes, note that it makes it shorter (by far).






                share|improve this answer













                The shortest one here:



                prevval=0
                for x,y in zip(list1,list2):
                print(x)
                print(' '.join(list3[prevval:prevval+y]))
                prevval+=y


                The output is:



                test
                hard to
                please
                come up with values


                zip them and iterate over, add prevval as usual, and remove the inner loop, that's all the changes, note that it makes it shorter (by far).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 4:43









                U9-ForwardU9-Forward

                16.6k51543




                16.6k51543













                • The problem with omitting the if statement is that if list3 = ["hard"] it'll print an empty list (or blank line in this case) which I'm not sure is desirable.

                  – slider
                  Nov 21 '18 at 4:51





















                • The problem with omitting the if statement is that if list3 = ["hard"] it'll print an empty list (or blank line in this case) which I'm not sure is desirable.

                  – slider
                  Nov 21 '18 at 4:51



















                The problem with omitting the if statement is that if list3 = ["hard"] it'll print an empty list (or blank line in this case) which I'm not sure is desirable.

                – slider
                Nov 21 '18 at 4:51







                The problem with omitting the if statement is that if list3 = ["hard"] it'll print an empty list (or blank line in this case) which I'm not sure is desirable.

                – slider
                Nov 21 '18 at 4:51













                0














                #!/bin/python

                list1 = ["test","please"]
                list2 = [2, 4, 6]
                list3 = ["hard", "to", "come", "up","with","values"]

                for i in list1:
                print(i)
                s =
                for j in range(list2.pop(0)):
                s.append(list3.pop(0))
                print(" ".join(s))


                Output:



                test
                hard to
                please
                come up with values





                share|improve this answer




























                  0














                  #!/bin/python

                  list1 = ["test","please"]
                  list2 = [2, 4, 6]
                  list3 = ["hard", "to", "come", "up","with","values"]

                  for i in list1:
                  print(i)
                  s =
                  for j in range(list2.pop(0)):
                  s.append(list3.pop(0))
                  print(" ".join(s))


                  Output:



                  test
                  hard to
                  please
                  come up with values





                  share|improve this answer


























                    0












                    0








                    0







                    #!/bin/python

                    list1 = ["test","please"]
                    list2 = [2, 4, 6]
                    list3 = ["hard", "to", "come", "up","with","values"]

                    for i in list1:
                    print(i)
                    s =
                    for j in range(list2.pop(0)):
                    s.append(list3.pop(0))
                    print(" ".join(s))


                    Output:



                    test
                    hard to
                    please
                    come up with values





                    share|improve this answer













                    #!/bin/python

                    list1 = ["test","please"]
                    list2 = [2, 4, 6]
                    list3 = ["hard", "to", "come", "up","with","values"]

                    for i in list1:
                    print(i)
                    s =
                    for j in range(list2.pop(0)):
                    s.append(list3.pop(0))
                    print(" ".join(s))


                    Output:



                    test
                    hard to
                    please
                    come up with values






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 21 '18 at 4:45









                    ConnerConner

                    23.6k84568




                    23.6k84568























                        0














                        list1 = ['test', 'please', 'this', 'works']
                        list2 = [2,4,6]
                        list3 = tmp = ['hard', 'to', 'come', 'up', 'with', 'values', 'because', 'it', 'is', 'simple', 'with', 'python']
                        for index, item in enumerate(list1):
                        try:
                        print(tmp[:list2[index]])
                        tmp = tmp[list2[index]:]
                        except:
                        break





                        share|improve this answer




























                          0














                          list1 = ['test', 'please', 'this', 'works']
                          list2 = [2,4,6]
                          list3 = tmp = ['hard', 'to', 'come', 'up', 'with', 'values', 'because', 'it', 'is', 'simple', 'with', 'python']
                          for index, item in enumerate(list1):
                          try:
                          print(tmp[:list2[index]])
                          tmp = tmp[list2[index]:]
                          except:
                          break





                          share|improve this answer


























                            0












                            0








                            0







                            list1 = ['test', 'please', 'this', 'works']
                            list2 = [2,4,6]
                            list3 = tmp = ['hard', 'to', 'come', 'up', 'with', 'values', 'because', 'it', 'is', 'simple', 'with', 'python']
                            for index, item in enumerate(list1):
                            try:
                            print(tmp[:list2[index]])
                            tmp = tmp[list2[index]:]
                            except:
                            break





                            share|improve this answer













                            list1 = ['test', 'please', 'this', 'works']
                            list2 = [2,4,6]
                            list3 = tmp = ['hard', 'to', 'come', 'up', 'with', 'values', 'because', 'it', 'is', 'simple', 'with', 'python']
                            for index, item in enumerate(list1):
                            try:
                            print(tmp[:list2[index]])
                            tmp = tmp[list2[index]:]
                            except:
                            break






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 21 '18 at 4:54









                            Thomas JohnThomas John

                            754521




                            754521























                                0














                                prevval = 0

                                val=0

                                for i in list1:

                                print(i)

                                val=list2[val]

                                print(list3[prevval:val])

                                prevval = val





                                share|improve this answer


























                                • Code only answers are discouraged. Always add a bit of explanation. Beyond that: make sure to nicely format indent all of your input, instead of just dumping text on others.

                                  – GhostCat
                                  Nov 21 '18 at 8:41
















                                0














                                prevval = 0

                                val=0

                                for i in list1:

                                print(i)

                                val=list2[val]

                                print(list3[prevval:val])

                                prevval = val





                                share|improve this answer


























                                • Code only answers are discouraged. Always add a bit of explanation. Beyond that: make sure to nicely format indent all of your input, instead of just dumping text on others.

                                  – GhostCat
                                  Nov 21 '18 at 8:41














                                0












                                0








                                0







                                prevval = 0

                                val=0

                                for i in list1:

                                print(i)

                                val=list2[val]

                                print(list3[prevval:val])

                                prevval = val





                                share|improve this answer















                                prevval = 0

                                val=0

                                for i in list1:

                                print(i)

                                val=list2[val]

                                print(list3[prevval:val])

                                prevval = val






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Nov 21 '18 at 9:44









                                vsync

                                48.4k36164223




                                48.4k36164223










                                answered Nov 21 '18 at 4:32









                                AnupritaAnuprita

                                285




                                285













                                • Code only answers are discouraged. Always add a bit of explanation. Beyond that: make sure to nicely format indent all of your input, instead of just dumping text on others.

                                  – GhostCat
                                  Nov 21 '18 at 8:41



















                                • Code only answers are discouraged. Always add a bit of explanation. Beyond that: make sure to nicely format indent all of your input, instead of just dumping text on others.

                                  – GhostCat
                                  Nov 21 '18 at 8:41

















                                Code only answers are discouraged. Always add a bit of explanation. Beyond that: make sure to nicely format indent all of your input, instead of just dumping text on others.

                                – GhostCat
                                Nov 21 '18 at 8:41





                                Code only answers are discouraged. Always add a bit of explanation. Beyond that: make sure to nicely format indent all of your input, instead of just dumping text on others.

                                – GhostCat
                                Nov 21 '18 at 8:41


















                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405155%2fprint-x-amount-of-items-y-times%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Guess what letter conforming each word

                                Port of Spain

                                Run scheduled task as local user group (not BUILTIN)