Skip to main content
0 votes
1 answer
59 views

In Python, I can unpack a list into individual variables: >>> name,age,date = ['Bob',20,'2025-1-1'] >>> name 'Bob' >>> age 20 >>> date '2025-1-1' In DolphinDB, I ...
RORO's user avatar
  • 1
1 vote
4 answers
162 views

My input is in the form of pairs of comma-separated values, e.g., 805i,9430 3261i,9418 3950i,9415 4581i,4584i 4729i,9421 6785i,9433 8632i,9434 9391i,9393i and I want to read them into a list of pair ...
Murray Patterson's user avatar
2 votes
1 answer
108 views

In python, we can unpack an iterable with a unary * like so: def foo(a, b, c): ... t = (1, 2, 3) foo(*t) In C++, I haven't encountered an equivalent. I'm aware that I could use structured ...
Octa's user avatar
  • 129
0 votes
1 answer
199 views

what seems to be the problem with the code l = [1,2,4,5,6,7,8] t = *l i have read that *l gives comma separated single values so the statement should be similar to t = 1,2,3,4,5,6,7 which is a tuple ...
Sachin Dobhal's user avatar
1 vote
3 answers
228 views

Sets don't have a deterministic order in Python. Why then can you do tuple unpacking on a set in Python? To demonstrate the problem, take the following in CPython 3.10.12: a, b = {"foo", &...
Zags's user avatar
  • 41.9k
1 vote
1 answer
60 views

Groovy can unpack lists or tuples with the spread operator (*), which looks like in Python. In Python we can partially unpack a tuple, like this: mytuple = ('a', 'b', 'c', 'd') first, *others = ...
PlasmaBinturong's user avatar
0 votes
3 answers
223 views

print can nicely unpack a tuple removing brackets and commas, e.g. a = (0, -1, 1) print(*a) produces 0 -1 1. Trying the same with f-strings fails: print(f'{*a}') The closest f-string option I found ...
Paul Jurczak's user avatar
  • 8,628
0 votes
3 answers
89 views

Can a tuple be unpacked to two tuples? E.g.: countries=("China","Japan","India","England","France") – unpack this tuple to two tuples, first tuple ...
Aliza Hashmi's user avatar
-1 votes
2 answers
44 views

Write a python class that gives the expected output Currently gives ValueError # Can be modified. (Can even be a function or generator class MyClass: def __init__(self): self.count = 0 ...
Dennis Jacob's user avatar
2 votes
4 answers
165 views

I am quite used to unpacking sequences in Python like: my_tuple = (1, 2, 3) a, b, c = my_tuple I have noticed that I can also do it with sets: my_set = set((1, 2, 3)) a, b, c = my_set Why can I do ...
Thomas Arildsen's user avatar
0 votes
0 answers
66 views

In newer versions, ROT_TWO is replaced by SWAP. However, after disassembling the function using dis.dis(), I noticed that SWAP does not appear in the bytecode. Python 3.9.0 >>> import dis >...
Jack's user avatar
  • 1
-1 votes
3 answers
101 views

I'm implementing an algorithm that requires appending and popping nodes from a Tree in python (in a FIFO way). queue = [] # empty list root = TreeNode() # a standard TreeNode with val, left and ...
user13079354's user avatar
5 votes
2 answers
174 views

Basic Facts Lists are mutable (supporting inserts, appending etc.), Tuples are not Tuples are more memory efficient, and faster to iterate over So it would seem their use-cases are clear. ...
Della's user avatar
  • 1,730
0 votes
1 answer
50 views

I tried to use list comprehension on a tuple and it worked fine when unpacking, but not when assigning to a single variable. If I run the following code var1, var2, var3 = (i for i in range(3)) var1 =...
Jme's user avatar
  • 3
0 votes
4 answers
81 views

I have a list of data (of varying type) that I need to process. It has fixed length and I know which index holds what data, so currently I do something like for x in data[:13]: do_stuff(x) for x in ...
Xoriun's user avatar
  • 180

15 30 50 per page
1
2 3 4 5
33