Questions tagged [mutable]

A mutable can be modified after it is created.

A mutable can be modified after it is created. It is a keyword in functional programming opposite to immutable.

Related tags:

1184 questions
-1
votes
1 answer

How to avoid arg kwargs to be non mutable?

I have a class A class A: __dict__ = {"x": 0} def __init__(self, **kwargs): self.__dict__.update(kwargs.copy()) When I create A objects: >>> a = A(x=2) >>> b = A(x=3) >>> print(a.__dict__) {x: 3} >>> print(b.__dict__) {x: 3} When I preset…
Just_Me
  • 111
  • 8
-1
votes
2 answers

How to run two setTimeout tasks in parallel?

I'm reading YDKJS and early on we are talking about the difference between Async, Parallel and Concurrent Code. I have a simple Async example: let output = 0; const bar = (cb) => setTimeout(cb, Math.random() * 1000); const foo = (cb) =>…
Armeen Moon
  • 18,061
  • 35
  • 120
  • 233
-1
votes
2 answers

Unable to swap multiple elements in a list in python

I'm new to python and am trying to make a function that swaps multiple values in a list at once. def swap(deck: List[int], start1: int, end1: int, start2: int, end2: int) -> None: start1 = start1 % len(deck) start2 = start2 % len(deck) …
JPJW
  • 1
  • 1
-1
votes
2 answers

Does Python automatically update variables whose value is another object?

Before asking, I read the accepted answer to the question "How do I pass a variable by reference?" and documentation linked in that same answer: "How do I write a function with output parameters (call by reference)?" I have a related question: Does…
Joachim Rives
  • 471
  • 6
  • 19
-1
votes
4 answers

How can I check if there is a duplicate list in a list of lists?

I have a list RESULT that contains lists. I want to add a list to RESULT only if it does not exist. So input = [1,2,3] RESULT = [[5,6], [4,5,8]] Now, RESULT.append(input) that gives RESULT = [[5,6], [4,5,8], [1,2,3]] Now if I try to append [5,6]…
Atihska
  • 4,803
  • 10
  • 56
  • 98
-1
votes
4 answers

Why isn't the value of the list changing even after I modify its value inside the function?

We know that lists in Python are mutable objects. However, the following code does not change the value of the list whose value is being modified inside a function. def change(l): l=l[2:5] return() l=[1,3,4,5,2,10] change(l) print (l) I…
-1
votes
1 answer

Why does StringBuffer return a reference?

public class doubleSum { private static String calculate(String a, String b){ String[] a_parts = a.split("\\."); String[] b_parts = b.split("\\."); StringBuffer sb = new StringBuffer(); int[] carrier = new…
-1
votes
2 answers

Add Tuple3 to a mutable Set in Scala

I have already looked at adding tuples to a Set in scala but nothing seems to work in my case val mySet = mutable.HashSet[(String, String, String)] val myTuple = ("hi", "hello", "there") mySet ++= myTuple mySet += myTuple // Expects String…
yalkris
  • 2,596
  • 5
  • 31
  • 51
-1
votes
2 answers

I heard that Haskell variables are immutable but i am able to reassign and update variable values

I heard that Haskell variables are immutable but i am able to reassign and update variable values
saketh
  • 317
  • 2
  • 10
-1
votes
1 answer

How do I implement move semantics on a struct with a mutable field?

I have a minimal example of code that implements move semantics for some container: use std::mem; impl<'a, T: 'a + ?Sized> Drop for Cointainer<'a, T> { fn drop(&mut self) {} } struct Cointainer<'a, T: 'a + ?Sized> { item: &'a /* mut */…
LOST
  • 2,956
  • 3
  • 25
  • 40
-1
votes
2 answers

How to make copy of MutableList in Kotlin?

So, I just started out with Kotlin and tried to solve "min steps for a knight to reach a destination on a chessboard" problem. Here is my code: fun knightSteps(i:Int,j:Int,a:Int,b:Int,board:Int,c :Int,d:Int,visited :…
SATHWIK MATSA
  • 43
  • 3
  • 6
-1
votes
3 answers

Python Class with ctypes attributes has side effects

I create a class for an image buffer. The class looks like this: import ctypes class ImgBuf(): def __init__(self, bufnr=ctypes.c_int(-1)): self.bufnr = bufnr The attribute 'bufnr' is handed over to a shared library by reference and…
smiddy84
  • 285
  • 1
  • 4
  • 13
-1
votes
1 answer

Using dicts as attributes in Python 3

Consider the following code in Python 3.5.2: class NewObj(): def __init__(self, refs={}): self.refs = refs class ObjA(NewObj): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) class ObjB(NewObj): …
Charlie
  • 469
  • 4
  • 15
-1
votes
2 answers

How to merge mutating numbers of lists into one in Python Speech Recognition?

I want to merge mutable lists into one. I am using speech recognition, so the lists of words that I am getting are changing all the time. Some people said to add lists using the + operator, but every time the speaker speaks, various numbers of lists…
-1
votes
2 answers

How to create an empty mutable list in python, so that list item can be added later?

I want to create an empty list in python so that I can add items into it later by a function. But when I tried to add items into it through function it showed me "TypeError: Can't convert 'tuple' object to str implicitly". Why am getting this? page…