Skip to main content
Filter by
Sorted by
Tagged with
-6 votes
3 answers
135 views

I'm taking a Coursera course on Python programming. There is a practice quiz on list comprehensions and tuples I'm failing by getting 2 questions wrong. But I don't think I got either question wrong. ...
Tony Vitabile's user avatar
3 votes
1 answer
145 views

I keep running into this weird roadblock when trying to use list comprehensions when trying to call on helper functions, and I'm unsure if I'm using the wrong tool for the job or I'm just missing a ...
Alfy B's user avatar
  • 167
-2 votes
1 answer
72 views

I am using a long ad hoc script for exploratory data analysis -- not for tool development. The script has gotten quite long, so I've taken to deling ephemeral variables to keep the Spyder Variable ...
user2153235's user avatar
  • 1,265
1 vote
1 answer
76 views

matrix1=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]] m2="\n".join(["\t".join([ritem for ritem in item]) for item in matrix1]) print(m2) where am i wrong that i receive this ...
mohammad saeed heidari's user avatar
0 votes
4 answers
50 views

I'm trying to a get a subset of elements of L1, which do not match with any element of another list >>> L1 = ["apple", "banana", "cherry", "date"] >&...
Susanta Dutta's user avatar
-3 votes
3 answers
96 views

I came across this scraping problem which itself is irrelevant but want to know if it is possible to perform map() from a list comprehension meaning the iterable be a list comprehension? The following ...
Ouroboros's user avatar
0 votes
2 answers
107 views

I have the following data, and what I'm want to do is bring into a new list of dicts those from task_resources that match on both the tasks_id and the qos_level: task_resources = [ { "...
Mark R's user avatar
  • 185
1 vote
2 answers
242 views

I have a list of numbers in Python, and I’m trying to get the sum of only the odd numbers. I know I can use a for loop, but is there a more Pythonic way to do this? Here’s what I have so far, but it ...
Mugginator's user avatar
0 votes
2 answers
455 views

I have 2 folders each containing 1507 csv files, i am using the following code to save each file as a polars dataframe using list comprehension: bdsim=[pl.read_csv(x, schema_overrides = {"X0.6&...
ELOY GARCIA's user avatar
-3 votes
2 answers
74 views

I am cleaning columns in a dataframe, and would like to split a "description" column based on certain keywords. I wrote a one liner but for some reason in still returns np.nan, even when the ...
user avatar
0 votes
3 answers
117 views

I am building a URL query, that allows the filtering of multiple fields. The filtering (e.g. from a form) is stored as pair values: column and FILTER. I am storing the filters as a list of pairs. I ...
markus1998's user avatar
0 votes
2 answers
76 views

tri_num = [] for i in range(1, 10): tri_num.append(i*(i+1)//2) print(tri_num) Hi, I'm taking a course in Python and we've been asked to write a list comprehension that creates ...
Schmied's user avatar
  • 11
-4 votes
3 answers
398 views

The general problem I have a case where I'm generating an element comprehension with a different cardinality to the input source. This cardinality should not be a multiple of the original (data-driven)...
Ricardo's user avatar
  • 879
-1 votes
3 answers
162 views

There is a dictionary: d = [{"a":1, "b":2},{"a":3, "b":4},{"a":5, "b":6}] I'd like to update values of keys b. d = [{**m}.update({"b&...
Honza S.'s user avatar
  • 310
0 votes
3 answers
81 views

I need to move the corner points of a rectangle by a given amount. I'm given an list of 4 3D points, each of which is a list of coordinates ([x,y,z]). I have this, and it works OK, but feels awkward (...
dogrocket's user avatar
1 vote
2 answers
108 views

I use list comprehension to load only the images from a folder that meet a certain condition. In the same operation, I would also like to keep track of those that do not meet the condition. This is ...
sabeansauce's user avatar
0 votes
2 answers
109 views

Can someone please help me find fault in my code? If I create a blank 2D matrix with static initial value, it returns the correct transposed matrix. Whereas if I create a blank matrix using a for loop,...
Suyash Nachankar's user avatar
3 votes
3 answers
175 views

I have a PySpark dataframe looking like this: id trx_holiday trx_takeout trx_pet max_value MAX 1 12.5 5.5 9.5 12.5 trx_holiday 2 3.0 14.0 6.7 14.0 trx_takeout I want to create a second column MAX_2 ...
NHUV's user avatar
  • 31
-1 votes
3 answers
71 views

I have a couple dictionaries with differing values for the same keys. I have a list of these dicts and I want to return the values from only 1 of the dicts based on the matched keys inside a different ...
AquaBearing's user avatar
-1 votes
1 answer
103 views

I have to create a Pandas dataframe from a csv file using a pipeline. The src csv file may contain any number of columns with header/name containing the string 'SLA'. Sample data below: While ...
rams's user avatar
  • 128
1 vote
1 answer
383 views

My aim is to create 2D vector elements in pairs, using a FOR loop. Consider the following example (not my real example - just something simplified to describe the problem): step1 = [ for (i=[1:5])...
Chris's user avatar
  • 13
1 vote
3 answers
72 views

The quiz problem is supposed to replace the file name .hpp with .h while keeping the rest using list comprehension. Some posts suggest that I must put in [do_something else if condition for x in range]...
Nubie coder's user avatar
-1 votes
1 answer
37 views

I have 2 lists. I want to find the elements in ls2 where any element of ls1 is a substring. I would like to return a list of ls2 elements along with the substring that was searched and found from ls1 ...
frank's user avatar
  • 3,816
0 votes
1 answer
120 views

I've created a Card object: class Card: def __init__(self, rank, suit, d=0): self.rank = rank self.suit = suit self.deck_index = d I can make a list of Cards that ...
WeCanDoItGuys's user avatar
-1 votes
1 answer
122 views

I'm working on a Python project where I need to filter a large list of dictionaries based on multiple conditions. Here's a simplified example of the data structure I'm dealing with: data = [ {&...
Wiltord's user avatar
  • 11

1
2 3 4 5
144