'How combine and output a list properly
the following code returns:
abc: [(2022, 5, 14, 13, 35, 57), -7]
I'm trying to get rid of the extra parenthesis after the 57
like this: abc = (2022, 05, 14, 13, 7, 42, -7)
here is my code:
abc = time.localtime()
list(abc)
abc = abc[:6]
abc = [abc] + [-7]
Solution 1:[1]
In python3 I would do:
abc=(*abc, -7)
instead of the posted line of code
abc = [abc] + [-7]
Some short explanations about the abc=(*abc, -7)
*abc does "unpack" the tuple abc into a list of single values.
Then whe append a value of -7 and create a new tuple containing all the values.
The original code [abc] stores the tuple contained in abc in a list with only one element (the tuple from abc). After that the value -7 is appended to the new list, resulting in a list with two elements. The first one beeing the tuple abc and the second element beeing the value -7.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
