Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm trying to get every combination of color and value and I don't know how to use the function islice

from itertools import islice
colur={"S", "H", "D", "C"}
val={"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}
for c in islice(colur,0,4):
 for v in islice(val,0,13):
  print( c,v )

I want it to print
S2
S3
S4
S5
S6
S7
S8
….

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This should be enough:

from itertools import product
colur={"S", "H", "D", "C"}
val={"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}
combinations = [f'{i[0]}{i[1]}' for i in product(colur, val)]

for i in combinations:
    print(i)

If you want your original order to be respected, change sets for lists (sets are unordered):

colur=["S", "H", "D", "C"]
val=["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
combinations = [f'{i[0]}{i[1]}' for i in product(colur, val)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading