set

Behaviour of set-intersection of objects

Behaviour of set-intersection of objects Question: I stumbled upon this uncertainty in one of my programs: Suppose we have a Class deriving from int with a custom attribute. class A(int): def __new__(cls, value, *args, **kwargs): return super(cls, cls).__new__(cls, value) def __init__(self, _, a): self.a = a Objects of this class are now used in a …

Total answers: 1

Creating sets of specific extracted values from a .txt file (Python)

Creating sets of specific extracted values from a .txt file (Python) Question: I have a .txt file that says "NAMES," "POINTS" and "SUMMARY" in capital letters, each followed by lines containing data. Each of these three groups is separated by an empty line: NAMES John Cena Sam Smith Selena Gomez POINTS sixteen forty thirty SUMMARY …

Total answers: 2

Search in set of sets

Search in set of sets Question: I would like to search in a set of sets in a specific way: Example (Pseudocode): search = {{1}, {3}} search_base = {{1, 2}, {3, 4}} # search results in True because the 1 can be found in the first set and the 3 in the second. Order doesn’t …

Total answers: 2

It sometimes reverse when I turn a string into a set

It sometimes reverse when I turn a string into a set Question: The string is: x = ‘ABBA’ whenever I use this code: x = ‘ABBA’ x = ”.join(set(x)) print(x) It results in: BA but I want it to be the first letters instead of the second letters: AB Is there any way that I …

Total answers: 2

Insert set values in same order they appear in code

Insert set values in same order they appear in code Question: All I want is insert to listbox items in the same order as in the set. I want it to be inserted like: ‘damp’->’camp’->’came’ and so on. How can I do that? gui_dict = tk.Listbox(third_task_window, width=10, height=10) words = {‘damp’, ‘camp’, ‘came’, ‘lame’, ‘lime’, …

Total answers: 1

Get item from set python

Get item from set python Question: I have a set which contains objects which I have the __eq__ and __hash__ functions defined for. I would like to be able to check if an object with the same hash is in the set and if it is in the set to return the object from the …

Total answers: 2

Python set.add() is triggering outside a conditional statement

Python set.add() is triggering outside a conditional statement Question: I’m tokenizing some document and I want to find out which tokens are shared between one or more tokenizations. To do this, for each tokenization, I am looping through the set of all tokens in all tokenizations, called all_tokens and checking if a given token exists …

Total answers: 2

multidimensional jax.isin()

multidimensional jax.isin() Question: i am trying to filter an array of triples. The criterion by which I want to filter is whether another array of triples contains at least one element with the same first and third element. E.g import jax.numpy as jnp array1 = jnp.array( [ [0,1,2], [1,0,2], [0,3,3], [3,0,1], [0,1,1], [1,0,3], ] ) …

Total answers: 1