How do I separate each list [closed]

2024/10/8 22:53:08

I'm very new to this and I don't know how to fix the problem. I have a Dealer and then it asks in the beginning how many players will be playing. Then each player as well as a Dealer get assigned 2 cards from a deck. The problem is that for example if I have 3 players the code lists the previous 2 cards from one player in the next as well.

Answer

You probably want a list per player. A dictionary will probably do the work, something like:

hands = {}
...
for player in players:hand = hands[player] = []for j in range(2):c = deck.pop()hand.append(c)for player in players:print('{}: {}'.format(player, ', '.join(hands[player])))
https://en.xdnf.cn/q/118662.html

Related Q&A

Why python doesnt see the members of quantumCircuit class qiskit

I`m trying to learn the programming on quantum computers. I have installed qiskit in VS Code (all qiskit extentions available in VS Code market) , python compilator (from Vs Code market "Python&qu…

Compare multiple lines in a text file using python

Im writing a program that is time tracking report that reports the time that was spent in each virtual machine, I`m having a problem comparing the txt file cause the only thing that changes are the num…

Error installing eomaps through conda and pip

I am getting the following error output when trying to install eomaps using Conda. I dont know how to solve this. I have also tried the same using pip but it didnt seem to solve the problem. Here is th…

DFS on a graph using a python generator

I am using a generator to do a full search on a graph, the real data set is fairly large, here is a portion of the code i wrote on a small data set:class dfs:def __init__(self):self.start_nodes = [1,2]…

Importing test libraries failed. No module named a

I have a folder /example which contains /Libs which further contains different folders /a, /b each containing python libraries. I am trying to run a robot framework code from /example.The error it show…

Sorting characters by count using PHP or Python

I have a string of charactersabcdefghijklmnopqrstuvwxyz_ I want to take this string of characters and sort them by the number of times they appear in a large block of characters. For example: cwrxwzb…

Save user first_name as default value for model django

I have an article model with author variable which I want to save as the users first and last name. I use custom user model called Account. author = models.CharField(author,max_length=50 default=User.f…

How to compare two imagefile from two different files in python

I would like to create a program that compares two images. I need to take images from two different folders and compare that images if they are same or not. Then I want to print out as same or differen…

Cant import from module despite presence of __init__.py

I have the following folder structureproject_folder/pyutils/__init__.pyscript1.pyscript2.py lambdas/__init__.pylambda_script1.pylambda_script2.pylambda_tests/__init__.pylambda_test1.pyWithin lambda_tes…

Multiple strings in one variable

Say, for example, I have some code that goes like this: sentence = input("Enter input: ") target_letter = "a" or "b" or "c" print(sentence.index(target_letter))M…