0

I have two lists, one with names and one with 4 scores for each player. All I want to do is have a dictionary or tuple (it doesn't matter, whichever would work better) that has the name and the four scores for them.

list1 = ['brian', 'lauren', 'bob']
list2 = ['12', '19', '45', '33', '10', '20', 51', '16', '38', '90', '66', '22']

the dictionary should look like:

finalDict = {"brian": 12, 19, 45, 33, "lauren": 10, 20, 51, 16, ect.}

Any help would be greatly appreciated!

kylieCatt
  • 10,672
  • 5
  • 43
  • 51
Kosmot199
  • 9
  • 5
  • 2
    Show us what you have tried so far :) – d-coder Oct 27 '14 at 04:53
  • Edit your question, don't add the code in a comment – kylieCatt Oct 27 '14 at 04:56
  • can't seem to get use to this comment section the way the "enter" key works. basically I know I need some type of "for" loop that iterates through both lists like: for item in list1, list2: dict = {list1[0], list2[0,3]} and so on – Kosmot199 Oct 27 '14 at 04:58
  • @Kosmot199 That sounds like a good place to start. – kylieCatt Oct 27 '14 at 05:02
  • Now i did just edit the code partially and I did figure out how to assign the list of names into a dictionary as the keys, but I temporarily put zeros. It prints out as info = {'brian':0, 'lauren':0, 'bob':0} – Kosmot199 Oct 27 '14 at 05:05
  • @Kosmot199 If only there were some way you could [slice](https://docs.python.org/2.3/whatsnew/section-slices.html) a list into smaller pieces ;-). – kylieCatt Oct 27 '14 at 05:10
  • Ok, I see where you're going, but could you show me an example of how to grab the first four, append them as values to the first key, then the following four for the second value? – Kosmot199 Oct 27 '14 at 05:14
  • @Kosmot199 I would really like to suggest a book http://www.diveintopython.net/toc/index.html – thavan Oct 27 '14 at 05:21

1 Answers1

0
def get_scores(names, scores):
    x, y, results = a_number, another_number, {}
    for name in names:
        results[name] = scores[y:x]
        x, y = x + an_amount, y + some_amount
    return results

This should get you started. a_number, another_number, an_amount and some_amount are place holders. I'll leave you to figure out what they should be. Some keywords for this example tuple assignment and list slicing.

Community
  • 1
  • 1
kylieCatt
  • 10,672
  • 5
  • 43
  • 51
  • Thank you very much! This made much more sense the way you did this versus how I was attempting this. I'll also be sure to check out that book you suggested. – Kosmot199 Oct 27 '14 at 15:15
  • @Kosmot199 If this answer solved your problem, please mark it as the solution so other who may have your problem will know it helps. It also gives the answer-er credit for spending time to help out :) – Parker Oct 27 '14 at 17:35
  • @Parker, thanks for the reminder. I'm still trying to get use to this website even though I've been programming for quite some time and have come here a lot. – Kosmot199 Oct 28 '14 at 03:38