list-comprehension

Splitting a nested list with a string value in python

Splitting a nested list with a string value in python Question: How would I be able to make a list comprehension that concatenates the input lists with and ‘X’ string as the separator. Note that the expected output will be string. The code below does not work please modify it. val = [[‘_’, ‘_’, ‘_’, …

Total answers: 1

Find the multiples of 3 or 5 but not 15 by using python

Find all multiples of 3 or 5 but not 15 using python Question: I want to find the multiples of 3 and 5 but not 15, in python by using list comprehension, list = [] a = [a for a in range(1,100) if ((a % 3 == 0) and (a % 5 == 0))] list.append(a) …

Total answers: 1

Evaluating a string as a numpy array

Evaluating a string as a numpy array Question: My team is migrating from Clickhouse to Azure Data Explorer (ADX). We are currently experiencing difficulties to query our data from ADX: the queried values are correct, but the data are read as a string rather than as an array of floats. Here is an example string: …

Total answers: 3

TypeError: 'int' object is not iterable with zip()

TypeError: 'int' object is not iterable with zip() Question: the question goes like this: revenue = [30000, 50000, 70000, 90000] cost = [10000, 15000, 20000, 30000] Write a comprehension together with the zip() function to make a new list that maintains profits. I tried doing it with for-loop: new_list = [] for revenue, cost in …

Total answers: 1

Compare two DataFrame columns of lists of strings (A & B) to find if any in B are NOT in A for adding to Col C

Compare two DataFrame columns of lists of strings (A & B) to find if any in B are NOT in A for adding to Col C Question: d = {‘Col A’: [[‘Singapore’,’Germany’,’UK’],[‘Ireland’,’Japan’,’Australia’],[‘India’,’Korea’,’Vietnam’]], ‘Col B’: [[‘Singapore’,’Germany’,’UK’],[‘Ireland’,’Japan’],[‘India’,’Mexico’,’Argentina’]]} df = pd.DataFrame(data=d) I’m trying to compare these two columns and return a new column, Col C, that contains any …

Total answers: 1

Efficient Filtering of Lists in a Dictionary of Lists

Efficient Filtering of Lists in a Dictionary of Lists Question: I’m working with some reasonably large datasets (500,000 datapoints with 30 variables each) and would like to find the most efficient methods for filtering them. For compatibility with existing code the data is structured as a dictionary of lists but can’t be converted (e.g. to …

Total answers: 2

Unpacking a list into multiple variables

Unpacking a list into multiple variables Question: Is there a way to unpack a list of lists, but into multiple variables? scores = [[‘S’, ‘R’], [‘A’, ‘B’], [‘X’, ‘Y’], [‘P’, ‘Q’]] Into: a = [‘S’, ‘R’], b = [‘A’, ‘B’], c = [‘X’, ‘Y’], d = [‘P’, ‘Q’] Seems like something that should be quite …

Total answers: 1