totally lost newbie

Steve Howell showell30 at yahoo.com
Sun May 27 10:21:18 EDT 2007


--- mark <j25bravo at gmail.com> wrote:

> Hi all
> 
> I posted earlier on this but have changed my
> approach so here is my
> latest attempt at solving a problem. I have been
> working on this for
> around 12 hours straight and am still struggling
> with it.
> 
> Write a program that reads the values for a random
> list of cards from
> a file, where each line in the file specifies a
> single card with the
> rank and then the suit separated by a space. The
> rank should be an
> integer in the range of 1 to 13 (Ace:1, King:13),
> while the suit
> should be a lower case character in the set { 'h',
> 'd', 'c', 's' }.
> Sort the card entries into suits ordered by rank,
> and print out the
> ordered list. Hint: sort the list first by rank, and
> then by suit.
> 

Given that the hint is to sort twice, you can first
break down the problem by just trying to sort your
list according to the number on the card, and don't
worry about the suit.  Also, try using a data file
that doesn't have any face cards in it, to keep things
simple at first.

Then, to get the face cards working, think about
this--a Jack is really just an 11, a Queen is just a
12, a King is just a 13, and an Ace is just a 1.

When you read in your data, maybe you want to just
work with the numbers internally?  Do you know how to
use a dictionary to map K to 13?

Then, when it comes time to produce the final output,
you'll need to map 13 back to 'K', which again
involves using a dictionary.

There are other approaches, too, just hope this sparks
some thought.







       
____________________________________________________________________________________Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=list&sid=396545433



More information about the Python-list mailing list