Questions tagged [multiple-assignment]
35 questions
1
vote
1 answer
How can these multiple assignments be simplified?
Can this code be simplified to a single assignment? The three variables are inputs I receive from the frontend. I’m using the xss module in Node.js.
var clientname = xss(req.body.clientName, {
whiteList: [],
stripIgnoreTag: true,
…

jjpp43
- 11
- 1
1
vote
3 answers
Python - Multiple Assignment
Recently I was reading through the official Python documentation when I came across the example on how to code the Fibonacci series as follows:
a, b = 0, 1
while a < 10:
print (a)
a, b = b, a + b
which outputs to 0,1,1,2,3,5,8
Since I've never…

Tom Brady
- 21
- 3
1
vote
3 answers
Is it possible to use parallel assignment for keys in Ruby hash?
Given that it is an immutable object, ruby allows paraller assignments as this:
sample[:alpha] = sample[:beta] = sample[:gamma] = 0
But is there any other simple way to do this? , something like :
sample[alpha:, beta:, gamma: =>…

Dwarakanath Thoppe
- 147
- 11
1
vote
1 answer
Lua digit pattern matching not capturing
I'm attempting to match Sword and 2 in the following string.
You receive loot [Sword]x2.
This is where I've made it so far. Sword matches fine and is saved in the item variable. qty, however, always returns 'No qty' regardless of the input…

ThinkingInBits
- 10,792
- 8
- 57
- 82
1
vote
2 answers
multiple assignments in one line for loop python
I would like a one line way of assigning two variables to two different values in a for loop.
I have a list of list of values
list_values = [[1, 2, 3], [4, 5, 6]]
I have tried to do this, and it works but is not pythony:
first = [i[0] for i in…

amc
- 813
- 1
- 15
- 28
0
votes
0 answers
How does multiple assignments on the same line work in JavaScript?
I couldn't find a similar thread as to this specific case, so I decided to make one.
Basically, let's consider this snippet.
let a = [7];
const b = a;
a[0] = a = 15;
console.log(a, b) // 15 [15]
According to MDN, the assignment operator goes…

kristalshards
- 9
- 2
0
votes
0 answers
variable assignment order in python comma-separated multiple assignment
I apologise since this question has been asked before, but I did not really understand the answer and the comments, but I do not have enough reputation to comment on those threads...
Changing variable order in Python comma-separated multiple…

fakeweeb69
- 11
- 2
0
votes
0 answers
Groovy: Multiple assignments not allowed in fields
When I tried to declare my variables using multiple assignment, it came up with the error
Multiple assignments not allowed in fields
class Ana {
def tmp = []
String subject
def (ini, sorted, full) = ['','',[:]]
…

user15620366
- 41
- 5
0
votes
0 answers
Groovy: command chain with dots and multiple assignments
I'm trying to understand why command chaining without dots is not working with multiple assignments. For example this dummy code:
def (one, two) = String.valueOf 12 trim() iterator()
Raises:
Script1.groovy: 2: expecting EOF, found '12' @ line 2,…

Faur Ioan-Aurel
- 791
- 1
- 7
- 18
0
votes
0 answers
How does the multiple assignment from in this case in python?
The below code is for revsesing a linked list given the head of the list
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
if head is None or head.next is None:
return head
prev =…
user13377268
0
votes
0 answers
Multiple Assignment output is not correct
I am trying to write a program where all the odd linked list nodes are pushed to the start of the linked list followed by the odd ones. What I have is below:
def oddEvenList(self, head: ListNode) -> ListNode:
sentinel = node1 = head
node2 =…

SDG
- 2,260
- 8
- 35
- 77
0
votes
1 answer
R: Dismembering a list/referring to the current environment
I am trying to write a function that can be used in the execution environment of a function that is the inverse operation to list, i.e., given a named list, it returns the named elements as named objects. This is what I…

andrewH
- 2,281
- 2
- 22
- 32
0
votes
1 answer
Bash/GitBash syntax for multiple variable value assignment not working when value is a command's output
I have GitforWindows 2.20.1 installed in Windows 7 64Bit.
Now as I stated in the question, the multiple variable assignment syntax is not always working, especially when the value to be assigned is a command's output, i.e.:
read -r a b c <<< $(echo…

Vicky Dev
- 1,893
- 2
- 27
- 62
0
votes
2 answers
Can't assign to operator .Multiple assignments in if statement in python
The 4th elif ending is throwing an error can't assign to operator.I am trying to design a tic tac toe game and assigning players X and 0 based upon their selection.can't assign to operator
def player_input(player):
marker = ''
while(marker…

Mahantesh
- 53
- 7
0
votes
1 answer
Making multiple assignments to objects named as strings
We can assign a value to a single object using that object's name - assign("x", 1) - and we can efficiently assign different values to multiple object thanks to the zeallot package - c(x, y) %<-% c(1, 2) - but can we do both? I basically just want…

DHW
- 1,157
- 1
- 9
- 24