Skip to content

Tag: list

More pythonic way of item_list[-1] != item_list[-2]?

I’m updating and then referring to the last item added to a list to determine an outcome, for example: I don’t need to refer to any other list element, just item_list[-1] & [-2]. Is there a more pythonic way of doing this? This code is for on_message using websockets, and the item_list is bein…

Remove elements from python list if they contain special characters

I have a python list of lists, where each row index represents a list of values. In some instances, the row values contain special characters. In the case that any list element in the row contains special characters, I want to remove that entire row from the list. Note that I want to do this without convertin…

Filter 2d list by another 2d list

I have a list A: And list B: I would like to leave only these rows in list A, that all values of which are contained in at least one row from list B. So my expected output is: Because values ‘512’ and ‘102’ are in second row of list B. I know how to achieve that by iterating or

Modifying the contents of a list Python

Here’s the coursera Google question prompt that I’m having issues with: The skip_elements function returns a list containing every other element from an input list, starting with the first element. Complete this function to do that, using the for loop to iterate through the input list Original Cod…