How to remove a specific randomly chosen element from a list?
up vote
1
down vote
favorite
So I'm doing a simple python game for a school project and it is like a playing card game. But i don't know how to remove the card I've played.
Basically, I have a pack of 7 cards and i randomly choose one card to be played if my attack > than opponents defese I won, and my card should not be used anymore. I'm doing all based on lists and strings, How can I remove the card who was randomly chosen?
baralho1=
baralho1 += random.sample(MasterList, 7)
print("nEste é o teu baralho:n",baralho1)
baralho2=
baralho2 += random.sample(MasterList, 7)
a=random.choice(baralho1)
How do I remove "a" from the "baralho1"?
python-3.x
New contributor
add a comment |
up vote
1
down vote
favorite
So I'm doing a simple python game for a school project and it is like a playing card game. But i don't know how to remove the card I've played.
Basically, I have a pack of 7 cards and i randomly choose one card to be played if my attack > than opponents defese I won, and my card should not be used anymore. I'm doing all based on lists and strings, How can I remove the card who was randomly chosen?
baralho1=
baralho1 += random.sample(MasterList, 7)
print("nEste é o teu baralho:n",baralho1)
baralho2=
baralho2 += random.sample(MasterList, 7)
a=random.choice(baralho1)
How do I remove "a" from the "baralho1"?
python-3.x
New contributor
2
it probably would be a better idea to generate pseudo-random index and pop card from list using it
– Azat Ibrakov
Nov 10 at 16:13
Do you want to remove 1 occurence ofa
, or all occurences?
– user202729
Nov 10 at 16:17
@user202729 all!!
– Henrique Sousa
Nov 10 at 18:03
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
So I'm doing a simple python game for a school project and it is like a playing card game. But i don't know how to remove the card I've played.
Basically, I have a pack of 7 cards and i randomly choose one card to be played if my attack > than opponents defese I won, and my card should not be used anymore. I'm doing all based on lists and strings, How can I remove the card who was randomly chosen?
baralho1=
baralho1 += random.sample(MasterList, 7)
print("nEste é o teu baralho:n",baralho1)
baralho2=
baralho2 += random.sample(MasterList, 7)
a=random.choice(baralho1)
How do I remove "a" from the "baralho1"?
python-3.x
New contributor
So I'm doing a simple python game for a school project and it is like a playing card game. But i don't know how to remove the card I've played.
Basically, I have a pack of 7 cards and i randomly choose one card to be played if my attack > than opponents defese I won, and my card should not be used anymore. I'm doing all based on lists and strings, How can I remove the card who was randomly chosen?
baralho1=
baralho1 += random.sample(MasterList, 7)
print("nEste é o teu baralho:n",baralho1)
baralho2=
baralho2 += random.sample(MasterList, 7)
a=random.choice(baralho1)
How do I remove "a" from the "baralho1"?
python-3.x
python-3.x
New contributor
New contributor
New contributor
asked Nov 10 at 16:10
Henrique Sousa
91
91
New contributor
New contributor
2
it probably would be a better idea to generate pseudo-random index and pop card from list using it
– Azat Ibrakov
Nov 10 at 16:13
Do you want to remove 1 occurence ofa
, or all occurences?
– user202729
Nov 10 at 16:17
@user202729 all!!
– Henrique Sousa
Nov 10 at 18:03
add a comment |
2
it probably would be a better idea to generate pseudo-random index and pop card from list using it
– Azat Ibrakov
Nov 10 at 16:13
Do you want to remove 1 occurence ofa
, or all occurences?
– user202729
Nov 10 at 16:17
@user202729 all!!
– Henrique Sousa
Nov 10 at 18:03
2
2
it probably would be a better idea to generate pseudo-random index and pop card from list using it
– Azat Ibrakov
Nov 10 at 16:13
it probably would be a better idea to generate pseudo-random index and pop card from list using it
– Azat Ibrakov
Nov 10 at 16:13
Do you want to remove 1 occurence of
a
, or all occurences?– user202729
Nov 10 at 16:17
Do you want to remove 1 occurence of
a
, or all occurences?– user202729
Nov 10 at 16:17
@user202729 all!!
– Henrique Sousa
Nov 10 at 18:03
@user202729 all!!
– Henrique Sousa
Nov 10 at 18:03
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
How do I remove "a" from the "baralho1"?
baralho1.remove(a)
Please read the documentation on mutable sequence types.
Thank you so much! It Worked!!! Now I can finish my project
– Henrique Sousa
Nov 10 at 18:08
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
How do I remove "a" from the "baralho1"?
baralho1.remove(a)
Please read the documentation on mutable sequence types.
Thank you so much! It Worked!!! Now I can finish my project
– Henrique Sousa
Nov 10 at 18:08
add a comment |
up vote
0
down vote
How do I remove "a" from the "baralho1"?
baralho1.remove(a)
Please read the documentation on mutable sequence types.
Thank you so much! It Worked!!! Now I can finish my project
– Henrique Sousa
Nov 10 at 18:08
add a comment |
up vote
0
down vote
up vote
0
down vote
How do I remove "a" from the "baralho1"?
baralho1.remove(a)
Please read the documentation on mutable sequence types.
How do I remove "a" from the "baralho1"?
baralho1.remove(a)
Please read the documentation on mutable sequence types.
answered Nov 10 at 16:14
ShadowRanger
55.6k44789
55.6k44789
Thank you so much! It Worked!!! Now I can finish my project
– Henrique Sousa
Nov 10 at 18:08
add a comment |
Thank you so much! It Worked!!! Now I can finish my project
– Henrique Sousa
Nov 10 at 18:08
Thank you so much! It Worked!!! Now I can finish my project
– Henrique Sousa
Nov 10 at 18:08
Thank you so much! It Worked!!! Now I can finish my project
– Henrique Sousa
Nov 10 at 18:08
add a comment |
Henrique Sousa is a new contributor. Be nice, and check out our Code of Conduct.
Henrique Sousa is a new contributor. Be nice, and check out our Code of Conduct.
Henrique Sousa is a new contributor. Be nice, and check out our Code of Conduct.
Henrique Sousa is a new contributor. Be nice, and check out our Code of Conduct.
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%2f53240821%2fhow-to-remove-a-specific-randomly-chosen-element-from-a-list%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
2
it probably would be a better idea to generate pseudo-random index and pop card from list using it
– Azat Ibrakov
Nov 10 at 16:13
Do you want to remove 1 occurence of
a
, or all occurences?– user202729
Nov 10 at 16:17
@user202729 all!!
– Henrique Sousa
Nov 10 at 18:03