how would you convert this code
poker_deck = [r+s for r in '23456789TJQKA' for s in 'SHDC']
to C#?
I came out with this:
char[] figures = "23456789TJQKA".ToCharArray();
char[] suites = "SHDC".ToCharArray();
List<string> deck = new List<string>();
foreach (var figure in figures)
{
foreach (var suite in suites)
{
deck.Add(string.Format("{0}{1}", figure, suite));
}
}
what do you think?
I would like to do the same in one simple and readable line
I think fluent LINQ would be a very readable solution as well as the solution that resembles your original Python code most:
Of course you can also write it in one line:
Because I code Python as well, this pleases my eye, seeing that it’s an almost literate translation of your comprehension 🙂