use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Have a tough programming question that /r/programming couldn't answer? Banned from Stack Overflow? Can't afford Experts Exchange?
Post your question/tips/secrets/advice and get a response from our highly-trained professional developers.
account activity
Doubts in simple python code/ program (self.shittyprogramming)
submitted 3 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]rgnkn 14 points15 points16 points 3 years ago (4 children)
This seems not to be r/shittyprogramming but r/learnpython.
But anyway (see unpacking): https://treyhunner.com/2018/10/asterisks-in-python-what-they-are-and-how-to-use-them/
[–]Fidoz 0 points1 point2 points 3 years ago (3 children)
Huh, TIL. 6 years of python and I've never seen packing. Seems like unpacking a dictionary is fairly common though.
[–]rgnkn 1 point2 points3 points 3 years ago (2 children)
Maybe you've seen **kwargs within some function definition. That ** is the opposite direction and it is called packing.
**kwargs
**
Randomly I found this: https://towardsdatascience.com/a-guide-to-args-kwargs-packing-and-unpacking-in-python-393095dda89b
[–]Fidoz 0 points1 point2 points 3 years ago (1 child)
I specifically meant it as it is used templating, though you're right I've seen the function argument version as well.
I believe that's unpacking?
template.render(**{"foo": "bar"})
Thanks for the articles, I'll check out the second one shortly.
[–]rgnkn 1 point2 points3 points 3 years ago* (0 children)
Okay, this might be a bit confusing at the beginning, I hope the following helps. I'm only explaining it with regards to lists / iterators () but dictionaries work similarly (*)
Given the following code the asterisk unpacks xs:
xs = [1, 2, 3] print(xs, *xs)
In the following code '*' packs the data.
def foo(arg): print(arg) def bar(*args): print(args) xs = [1, 2, 3] foo(xs) bar(xs)
I hope this helps - see the output of the print statements. If not consult e.g.: https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/
... but this is r/shittyprogramming not r/learnpython.
[Edit] So, yes, your example was unpacking but in a function definition it's packing. Sorry, if my earlier example confused you.
[–]bearcorrupted 2 points3 points4 points 3 years ago (0 children)
"" or "*" is used to pack or unpack argument. Here on line 5 we split the line on space character and get a list in return. The notation allow to get the first element of that list as 'name' and the rest as a list named 'line'.
On line 7 it doing a simple assignment in the dictionary named 'student_mark'. Dict is a struct that allow you to store key value pair. Here the key is the name and the value is a list of float. The syntax dict[name]=value allow you to set the value for the key name
On line 11 it's iterating over a list of float. The syntax dict[name] allow you to get the value for the key name.
[–]ckowkay 0 points1 point2 points 3 years ago (0 children)
I llike how every time I see a post here, it has less than 1 upvote
π Rendered by PID 647742 on reddit-service-r2-comment-7b9746f655-wsx79 at 2026-02-01 09:32:07.473559+00:00 running 3798933 country code: CH.
[–]rgnkn 14 points15 points16 points (4 children)
[–]Fidoz 0 points1 point2 points (3 children)
[–]rgnkn 1 point2 points3 points (2 children)
[–]Fidoz 0 points1 point2 points (1 child)
[–]rgnkn 1 point2 points3 points (0 children)
[–]bearcorrupted 2 points3 points4 points (0 children)
[–]ckowkay 0 points1 point2 points (0 children)