Print 'x' amount of items 'y' times?
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
|
show 6 more comments
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
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 wantval += j
instead ofval = j
?
– NotAnAmbiTurner
Nov 21 '18 at 4:17
2
where does that1
come from in your desired output?
– Kevin Fang
Nov 21 '18 at 4:26
|
show 6 more comments
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
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
python list
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 wantval += j
instead ofval = j
?
– NotAnAmbiTurner
Nov 21 '18 at 4:17
2
where does that1
come from in your desired output?
– Kevin Fang
Nov 21 '18 at 4:26
|
show 6 more comments
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 wantval += j
instead ofval = j
?
– NotAnAmbiTurner
Nov 21 '18 at 4:17
2
where does that1
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
|
show 6 more comments
6 Answers
6
active
oldest
votes
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]))
Might you not get anIndexError
ifprevval + i >= len(list3)
? (eg. a shortlist3
)
– 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
add a comment |
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
add a comment |
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).
The problem with omitting theif
statement is that iflist3 = ["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
add a comment |
#!/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
add a comment |
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
add a comment |
prevval = 0
val=0
for i in list1:
print(i)
val=list2[val]
print(list3[prevval:val])
prevval = val
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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]))
Might you not get anIndexError
ifprevval + i >= len(list3)
? (eg. a shortlist3
)
– 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
add a comment |
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]))
Might you not get anIndexError
ifprevval + i >= len(list3)
? (eg. a shortlist3
)
– 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
add a comment |
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]))
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]))
answered Nov 21 '18 at 4:34
sliderslider
8,49811331
8,49811331
Might you not get anIndexError
ifprevval + i >= len(list3)
? (eg. a shortlist3
)
– 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
add a comment |
Might you not get anIndexError
ifprevval + i >= len(list3)
? (eg. a shortlist3
)
– 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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 21 '18 at 4:38
NotAnAmbiTurnerNotAnAmbiTurner
768522
768522
add a comment |
add a comment |
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).
The problem with omitting theif
statement is that iflist3 = ["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
add a comment |
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).
The problem with omitting theif
statement is that iflist3 = ["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
add a comment |
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).
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).
answered Nov 21 '18 at 4:43
U9-ForwardU9-Forward
16.6k51543
16.6k51543
The problem with omitting theif
statement is that iflist3 = ["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
add a comment |
The problem with omitting theif
statement is that iflist3 = ["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
add a comment |
#!/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
add a comment |
#!/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
add a comment |
#!/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
#!/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
answered Nov 21 '18 at 4:45
ConnerConner
23.6k84568
23.6k84568
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 21 '18 at 4:54
Thomas JohnThomas John
754521
754521
add a comment |
add a comment |
prevval = 0
val=0
for i in list1:
print(i)
val=list2[val]
print(list3[prevval:val])
prevval = val
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
add a comment |
prevval = 0
val=0
for i in list1:
print(i)
val=list2[val]
print(list3[prevval:val])
prevval = val
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
add a comment |
prevval = 0
val=0
for i in list1:
print(i)
val=list2[val]
print(list3[prevval:val])
prevval = val
prevval = 0
val=0
for i in list1:
print(i)
val=list2[val]
print(list3[prevval:val])
prevval = val
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 ofval = 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