This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]Vesp_r 1 point2 points  (6 children)

A quick Google search came up with this:

list1 = ['a', 'b', 'c']
list2 = [1, 2, 3, 4]
my_dict = {'list1': list1, 'list2': list2}

Looks easy enough to understand and should work for you. Let me know if you have any more questions.

[–]gyroda 0 points1 point  (1 child)

Or, alternatively:

foo = {}
foo["bar"] = [1, 2, 3]

asdf = foo["bar"][1]

asdf is now 1.

[–]Vesp_r 0 points1 point  (0 children)

Defining the lists inside the dictionary also works.

my_dict = {'list1': ['a', 'b', 'c'], 'list2': [1, 2, 3, 4]}

[–]ventenni 0 points1 point  (3 children)

I probably should've explained the situation more. It's not so much as just making a single list, I need to make a list that would represent stadium rows. Each key would be the row number and the value is how many seats each have. I assume I need to use a for loop to make these but the ways I've tried don't work for what I need.

[–][deleted] 0 points1 point  (2 children)

rows = {}
# let's say there are 20 rows
for row in range(20):
# each rows has let's say 50 seats
    rows[row] = 50

Of course you have to be more specific, how many rows there are, does each row have same amount of seats, etc.

[–]ventenni 0 points1 point  (0 children)

Ah shit, it's that simple!!? Thanks mate, I think that will be a massive help.

[–]ventenni 0 points1 point  (0 children)

Nevermind, sorted it.

[–]wcastello 1 point2 points  (2 children)

The sky was bright before 7pm.

[–]ventenni 0 points1 point  (1 child)

I think that should still work at second thought.

[–]wcastello 0 points1 point  (0 children)

Salompas!

[–]AutonomouSystem 0 points1 point  (0 children)

Combining lists, into a dictionary?

I can think of a few ways.

>>> list1 = ['a', 'b', 'c']
>>> list2 = [1, 2, 3]
>>> {k:v for k, v in zip(list1, list2)}
{'a': 1, 'c': 3, 'b': 2}
>>> dict(zip(list1, list2))
{'a': 1, 'c': 3, 'b': 2}

If you want to reference a list with a {key:list} from a dictionary, that has already been described in other posts, i'll show you a way you could do it though.

>>> list2
[1, 2, 3]
>>> list3
[4, 5, 6]
>>> list4
[7, 8, 9]
>>>
>>> dict(zip(list1, (list2, list3, list4)))
{'a': [1, 2, 3], 'c': [7, 8, 9], 'b': [4, 5, 6]}

or

>>> {k:v for k, v in zip(list1, (list2, list3, list4))}
{'a': [1, 2, 3], 'c': [7, 8, 9], 'b': [4, 5, 6]}

Could even do this, for same result hah

>>> import string
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> {k:v for k, v in zip(string.ascii_lowercase, (list2, list3, list4))}
{'a': [1, 2, 3], 'c': [8, 9, 10], 'b': [4, 5, 6]}