list

Why does "set(a) and set(b)" vs "set(a) & set(b)" give different results in python?

Why does "set(a) and set(b)" vs "set(a) & set(b)" give different results in python? Question: I understand that one is bitwise operation while the other is not, but how does this bitwise property affect the results of given expression. As both should simply compare the elements in both sets and result in common elements. set(a) …

Total answers: 1

How to split a nested list into separate lists?

How to split a nested list into separate lists? Question: I have a list as follows [[‘Norm,Macdonald’, ’61’, ‘459000’], [‘Paul,McCartney’, ’79’, ‘2789000’], [‘Samuel,Hui’, ’73’, ‘538000’]] For the desired output it would be something like [[‘Norm’, ‘Macdonald’, ’61’, ‘459000’], [‘Paul’, ‘McCartney’, ’79’, ‘2789000’], [‘Samuel’, ‘Hui’, ’73’, ‘538000’]] How should I split it to make it look …

Total answers: 5

Obtaining information from a list/dict in Python

Obtaining information from a list/dict in Python Question: I understand this question may have been asked in many different formats in the past. I also checked the recommended answers when I wrote the question title, and I haven’t found what I need. I’m new to Python so my understanding of lists and dictionaries is slowly …

Total answers: 2

How can I use sympy sum over elements of a list in python?

How can I use sympy sum over elements of a list in python? Question: I am just trying to use a sympy sum over a list of elements, for example: x = [1,2,3,4,5] expression = sympy.sum(x[i], (i,0,2)) * sympy.sum(x[j], (j,1,3)) and I just want it to numerically evaluate this. I always get index out of …

Total answers: 1

Create one long string from multiple lists of strings

Create one long string from multiple lists of strings Question: I am writing this back-end code to filter through a dataframe using df.query(). I have two lists from which I need to make this new string which will be passed as the query. Can anyone help me out? list1 = [‘Product == "Dress"’, ‘Product == …

Total answers: 4

Group a list of strings by similar values

Group a list of strings by similar values Question: I want to group a list of strings by similarity. In my case (here simplified cause this list can be huge) it’s a list of path to zip files like this: ["path/002_AC_HELICOPTEROS-MARINOS_20230329_210358_145T3_21049_00748_DMAU.zip", "path/002_AC_NOLAS_20230326_234440_145T2_20160_06473_VMS_UMS.zip", "path/002_AC_HELICOPTEROS-MARINOS_20230329_211105_145T3_21049_00748_FDCR.zip", "path/002_AC_HELICOPTEROS-MARINOS_20230329_205916_145T3_21049_00747_VMS_UMS.zip", "path/002_AC_NOLAS_20230326_235504_145T2_20160_06473_FDCR.zip"] I would like to group the strings in that list …

Total answers: 2

generate a new dictionary based on list of values

generate a new dictionary based on list of values Question: I have an input dictionary d1 and list l1 and want to generate output dictionary d2. d1 = {‘A1’:[‘b1′,’b2′,’b3’], ‘A2’:[‘b2’, ‘b3’], ‘A3’:[‘b1’, ‘b5’]} l1 = [‘b2’, ‘b5’, ‘b1’, ‘b3’] Output dictionary d2 = {‘b2’:[‘A1′,’A2’], ‘b5’:[‘A3’], ‘b1’:[‘A1′,’A3’], ‘b3’:[‘A1′,’A2’]} In output dictionary all values of list l1 …

Total answers: 1

How to skip one loop in a for loop?

How to skip one loop in a for loop? Question: I’m trying to make a really simple code that works sort of like wordle. It gets a random 5 letter word and asks the user to guess the word. The code will then output if a letter was in the word and if the letter …

Total answers: 1