set

Mapping set operations in python

Mapping set operations in python Question: I have a very simple problem, but today, I confess I have trouble finding the solution: I want to use the ‘&’ operator on python sets, but I don’t know how many sets I will have to deal with. Is it possible to use a mapping with python to …

Total answers: 1

Python how to get ordered set with the same API as regular set?

Python how to get ordered set with the same API as regular set? Question: I know from other posts on this site that (1) sets in python are not ordered but (2), in modern versions of Python a good way to get an ordered set is to use a dictionary (which now preservers key/value insertion …

Total answers: 1

Is there something wrong with the way I am using sets in python?

Is there something wrong with the way I am using sets in python? Question: I want to use sets to check for anagram, and I think I am doing it correctly. First I add all elements of string A to the set and then returning a flag based on elements of string B. def return_anagram(a, …

Total answers: 1

Create set from python loop output and remove duplicates

Create set from python loop output and remove duplicates Question: I’ve researched the options already available on stack overflow, but none have helped given my lack of understanding of python. I have the following code, which gives the below output. I would like to understand how to remove the duplicate lines from the output itself …

Total answers: 2

How to get all data from set

How to get all data from set Question: So, it`s my data in list [(‘AED’, Decimal(‘3.67303’)), (‘AFN’, Decimal(‘89.408409’)), (‘ALL’, Decimal(‘118.735882’)), (‘AMD’, Decimal(‘420.167855’)), (‘ANG’, Decimal(‘1.803593’)), (‘AOA’, Decimal(‘431.906′))] And I did this but only for first element: Currency: AED, Value: 3.67303 for key, val in query: return f’Currency: {key}, Value: {val}’ How can I do this for …

Total answers: 4

Conditionally set particular cell (index, 'column') value in dataframe in Python

Conditionally set particular cell (index, 'column') value in dataframe in Python Question: I need to conditionally set value of each row of a particular column in a dataframe. If the condition meets then the particular cell should be changed according to variable provided in the list, otherwise it should remain as it is. Please find …

Total answers: 2

performance problem, code works but consider takes long time in long list

performance problem, code works but consider takes long time in long list Question: why the following code is consider inefficient in terms of time complexity and how can I improve it? The time complexity for ia in n takes o(n) hence the problem. what have I tired? I sorted initially n,a and b but no …

Total answers: 3

How to find intersection of two sentences and include substrings

How to find intersection of two sentences and include substrings Question: I am comparing sentences with jaccard similarity in Python. However, I have a question for the intersection function: import itertools import pandas as pd item1=’She went to a restaurant on Oxford Street’.split(‘ ‘) item2=’She went to an Italian restaurant on Oxf. Street’.split(‘ ‘) set.intersection(*[set(item1), …

Total answers: 2

How to chain Python's set.add() while updating dictionary values being sets?

How to chain Python's set.add() while updating dictionary values being sets? Question: Let’s create dictionary dctD entries with values being set()s: dctD = {‘key0’:set([‘value0’])} # static constant (key, value) pair dctD[‘key1’] = set([‘value1’]) # static constant (key, value) pair Now the dictionary has to be updated with a new value which should extend its set() …

Total answers: 2