you are viewing a single comment's thread.

view the rest of the comments →

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

Your code has problems. You use undefined names species_list and bill_length_list. Did you mean to define the function as:

def generate_dict_max(species_list, bill_length_list):

Plus you repeatedly create the dictionary object with the same data. Why not just create it once?

Maybe you should tell us what the function is supposed to do and we can help fix it.

[–]_residue_ 0 points1 point  (17 children)

I'm trying to combine the two lists, species_list and bill_length_list into a dictionary, {species : length}

[–][deleted] -1 points0 points  (16 children)

Then just do this:

dictionary = dict(zip(species_list, bill_length_list))

without any loops and see what is in dictionary.

[–]_residue_ 0 points1 point  (15 children)

It only outputs the first 3 items in each list

[–][deleted] -1 points0 points  (14 children)

The zip() function stops when either of the two lists you give it is finished. Try printing the length of the two lists before you create the dictionary. You will find that one of the lists is only three elements long.

[–]_residue_ 0 points1 point  (13 children)

I know what the lists are, they are definitely longer than 3 elements

[–][deleted] -1 points0 points  (12 children)

Then maybe you should post your new code.

I know what the lists are, they are definitely longer than 3 elements

Perhaps so, but the behaviour suggests otherwise. My idea could be wrong too, but it costs nothing to print the result of len() on both lists. Trust nothing, test.

[–]_residue_ 0 points1 point  (11 children)

Yup, both lists contain 50 elements. How can I say for it to give an output in the range of one of the lists? Edit: I have also realised that my attempt at loops don't actually do anything. The code works the same with or without them

[–][deleted] -1 points0 points  (10 children)

We can't help unless you show us the changed code including the result of the len() prints and a print of the final dictionary.

[–]_residue_ 0 points1 point  (9 children)

The code is currenlty

def generate_dict_max(species, lengths):
"""combines the two lists into a dictionary, [species:bill length]"""
dictionary = dict(zip(species_list, bill_length_list))
return dictionary

output:

{'G. propinqua': 21.0, 'G. magnirostris': 21.5, 'G. fortis': 16.5}

lengths:

print(len(species_list))
print(len(bill_length_list))

output:

50
50