I am having my first ever Python exam this Monday, and am naturally very nervous! I am currently going through some old exams and this question appeared: “What result of the following code will appear on the terminal?” I tested it, and the answer is 1. However, I can’t seem to wrap my head around why. If anyone would be
Tag: list
How do you eliminate items from nested lists
Given a list of ranked ballots and a list of candidates to eliminate, I need to return a new list of ranked ballots where all the candidates in the list of candidates to eliminate have been removed. This is the code I’ve tried so far My first doctest is failing, giving me this output instead: Answer This is the function
How do I remove ‘None’ items from the end of a list in Python
A have a list that might contain items that are None. I would like to remove these items, but only if they appear at the end of the list, so: I have written a function, but I’m not sure this is the right way to go about it in python?: Also a list comprehension as an alternative, but this seems
Numba cannot determine fingerprint of empty list even with signature
I am using the @jit signature to define the types of the incoming arguments. But in calling the function I get: I know the list is empty, but my signature defines it so am not sure why Numba does not use that signature. I have tried the different forms of signatures (string form and the tuple form) and it still
How to select range with input user in list
I want to select a range between elements in a list, but instead of putting, for example, item 7, I put what I’m seeing in elements. The number between ‘document’ and ‘35621’ changes, I need to convert these numbers to a range (I think?) I don’t really know how to make this. For example, in my list I have: I
Snail Algorithm – controlling Max/Min position for traversal
I’m working on a problem in CodeWars for fun, and I’m having trouble with a couple of things: Understanding where I need to modify the code in order to properly control the “turning point” of m and n so that they begin decreasing rather than increasing. Refactoring this code appropriately. The purpose of the algorithm is to traverse a 2D
Python: Proper use of any() to check if one value of one array exists in another array?
In Python, I am trying to create an if statement that proceeds if one variable of one array exists somewhere in another list or array. Here is my basic code, which is supposed to check if any of the values within ids exist in follow_num: Despite my best attempts, and many versions of the above, I cannot get this to
Getting indices of ascending order of list
I know that this question has been asked a hundred times, but the answer always seems to be “use numpy’s argsort”. But either I am misinterpreting what most people are asking, or the answers are not correct for the question. Whatever be the case, I wish to get indices of a list’s ascending order. The phrasing is confusing, so as
Split list at a specific value
I am trying to write a code that splits lists in a class of lists in two when a certain value is a middle element of the list and then produce two lists where the middle element becomes the end element in the first list and the first element in the second one. There can be more than n middle
In-place modification of Python lists
I am trying to perform in-place modification of a list of list on the level of the primary list. However, when I try to modify the iterating variable (row in the example below), it appears to create a new pointer to it rather than modifying it. Smallest example of my problem. The above example is a trivial example of my