mutable Questions

6

Solved

Can anyone help me solve this issue? ImportError: dlopen(/Users/......./venv/lib/python3.6/site-packages/recordclass/mutabletuple.cpython-36m-darwin.so, 2): Symbol not found: __PyEval_GetBuiltinId...
Sportsmanship asked 19/3, 2020 at 16:22

10

Since Python's strings are immutable, it's inefficient to edit them repeatedly in loops. How can I use a mutable data structure to implement string operations, so as to avoid making lots of tempora...
Corneous asked 12/11, 2013 at 10:0

19

Solved

I created a list of lists: >>> xs = [[1] * 4] * 3 >>> print(xs) [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] Then, I changed one of the innermost values: >>> xs[0][0] = 5 ...
Burford asked 27/10, 2008 at 14:57

20

I'm confused on what an immutable type is. I know the float object is considered to be immutable, with this type of example from my book: class RoundFloat(float): def __new__(cls, val): return f...
Joletta asked 8/11, 2011 at 19:41

4

Editor's note: This question predates Rust 0.1 (tagged 2013-07-03) and is not syntactically valid Rust 1.0 code. Answers may still contain valuable information. Does anyone know how to create mut...
Citizenship asked 27/10, 2012 at 18:9

4

Solved

I have a struct which I put in a List<T>, I want to edit some value in that struct at a specific position. Is this at all possible without making a copy of the struct, editing the copy, and r...
Wageworker asked 21/11, 2012 at 1:4

2

Solved

Example code could be found below or on godbolt. Say we have 4 classes: S<T>: holding a data member. SCtor<T>: holding a data member and has a template constructor. SCtorMutable<T...

8

Do you know of a Python library which provides mutable strings? Google returned surprisingly few results. The only usable library I found is http://code.google.com/p/gapbuffer/ which is in C but I ...
Canzone asked 13/5, 2012 at 14:45

3

Solved

I have a list which is a private member in my class. I have used getter and setter to get and set the values. SOnar throws an error - Mutable members should not be stored or returned directly. For...
Crocodile asked 8/1, 2019 at 12:28

7

Solved

I am still not sure about the rules of struct copy or reference. I want to mutate a struct object while iterating on it from an array: For instance in this case I would like to change the backgrou...
Calendula asked 21/4, 2015 at 16:20

24

Solved

While using new_list = my_list, any modifications to new_list changes my_list every time. Why is this, and how can I clone or copy the list to prevent it?
Saltpeter asked 10/4, 2010 at 8:49

5

Solved

I seems to miss some point in lambda mechanism in C++. Here is the code: std::vector<int> vec (5); int init = 0; std::generate(begin(vec), end(vec), [init]() mutable { return ++init; }); f...
Germanize asked 14/5, 2016 at 0:43

14

Solved

Can anyone amend namedtuple or provide an alternative class so that it works for mutable objects? Primarily for readability, I would like something similar to namedtuple that does this: from Came...
Convolute asked 26/3, 2015 at 22:56

4

Solved

I have been playing around with dataclasses dynamically loaded with property names from a file and I am unable to find a way to create both 'frozen' and 'non-frozen' properties. I believe dataclass...
Stinko asked 23/10, 2019 at 23:58

5

Solved

I have a list: val someList = listOf(1, 20, 10, 55, 30, 22, 11, 0, 99) And I want to iterate it while modifying some of the values. I know I can do it with map but that makes a copy of the list. ...
Icsh asked 5/1, 2016 at 9:47

4

Solved

How to do that without creating any new collections? Is there something better than this? val m = scala.collection.mutable.Map[String, Long]("1" -> 1, "2" -> 2, "3" -> 3, "4" -> 4) m.f...
Gushy asked 23/3, 2010 at 14:12

4

Solved

Here are two function signatures I saw in the Rust documentation: fn modify_foo(mut foo: Box<i32>) { *foo += 1; *foo } fn modify_foo(foo: &mut i32) { *foo += 1; *foo } Why the differen...
Karimakarin asked 18/2, 2015 at 15:46

4

Solved

I think I may be failing to understand how mutable collections work. I would expect mutable collections to be affected by applying map to them or adding new elements, however: scala> val s: col...
Yaakov asked 2/8, 2011 at 9:17

3

Solved

Are Strings mutable in Ruby? According to the documentation doing str = "hello" str = str + " world" creates a new string object with the value "hello world" but when we do str = "hello" str ...
Socinus asked 16/4, 2011 at 12:53

3

Solved

I couldn't find an answer in both stackoverflow and the Julia docs to the following "design problem": Let's say I want to define the following object struct Person birthplace::String age::Int end...
Heterogamete asked 23/1, 2018 at 12:5

3

Solved

I'm new in Rust and i'm trying to allocate computational work to threads. I have vector of strings, i would want to create to each string one thread to do his job. There's simple code: use std::thr...
Doubleness asked 19/2, 2022 at 4:14

4

Solved

I would like to write a Python function that mutates one of the arguments (which is a list, ie, mutable). Something like this: def change(array): array.append(4) change(array) I'm more familia...
Salesin asked 24/9, 2014 at 22:38

2

Solved

Is there a way to check if a type is mutable or immutable? Can this check be done at compile-time (i.e. have branches if ismutable(T) compile away to just use the codepath for either mutability or ...
Chairwoman asked 20/11, 2016 at 17:18

2

Solved

In many cases, many member-functions could be specified 'const' - they don't modify any data-members of the class ...almost: they do lock/unlock the class mutex. Is it a good practice to specify, i...
Zeitgeist asked 26/12, 2021 at 19:16

5

Solved

According to the specification, strings that are used as a key to a hash are duplicated and frozen. Other mutable objects do not seem to have such special consideration. For example, with an array ...
Meli asked 24/10, 2012 at 7:44

© 2022 - 2025 — McMap. All rights reserved.