please help me on this homework:
makeA({0: 1, 2: 1, 4: 2, 6: 1, 9: 1})
the output should be like this:
[1, 0, 1, 0, 2, 0, 1, 0, 0, 1]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try a list comprehension:
The first line of the function body finds the maximum key in the dict (because
dictobjects yield their keys when iterated over). If the maximum key is 5, you’d need an array of 6 elements [0..6].The last line uses a list comprehension over a sequence
0 .. maxElem, and for each value of this sequence, assigns eitherd‘s value for this key or 0 if not present.