Skip to content
Advertisement

Tag: list

What is the process of this code, and why is the answer 1?

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

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

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

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

Advertisement