Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
Way back when, you could ask, eg, Quake (2?), to search for nearby servers, and it would list multiplayer servers in your geographical area (or anyway according to some number of network hops). What is the name of this type of network-crawl service discovery?

Adbot
ADBOT LOVES YOU

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Newf posted:

Way back when, you could ask, eg, Quake (2?), to search for nearby servers, and it would list multiplayer servers in your geographical area (or anyway according to some number of network hops). What is the name of this type of network-crawl service discovery?

Tangentially related, your question made me remember the old days of finding multiplayer servers thru GameSpy.

nielsm
Jun 1, 2009



Newf posted:

Way back when, you could ask, eg, Quake (2?), to search for nearby servers, and it would list multiplayer servers in your geographical area (or anyway according to some number of network hops). What is the name of this type of network-crawl service discovery?

In the case of games, it can be called a Master Server.

Hughmoris posted:

Tangentially related, your question made me remember the old days of finding multiplayer servers thru GameSpy.

I don't think QuakeWorld or Quake 2 had any built-in internet game browser, and you'd use QuakeSpy (later GameSpy when it expanded to more games) to query their master server to find games. I don't remember if the games had built-in registration to the master server or not.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

Hughmoris posted:

Tangentially related, your question made me remember the old days of finding multiplayer servers thru GameSpy.

Holy smokes that icon is a trip.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

nielsm posted:

In the case of games, it can be called a Master Server.

Maybe I'm crazy, but I don't think this was a case of server registration. I *believe* it was pinging adjacent IP addresses and propagating out breadth-first style. EG, there were two major local ISPs at the time, and users from service A would find servers only from service A, and similar for service B.

nielsm
Jun 1, 2009



Newf posted:

Maybe I'm crazy, but I don't think this was a case of server registration. I *believe* it was pinging adjacent IP addresses and propagating out breadth-first style. EG, there were two major local ISPs at the time, and users from service A would find servers only from server A, and similar for service B.

You can do UDP broadcast, but it's quite limited.
If you send a UDP datagram to 255.255.255.255 (in IPv4) then it'll get broadcast to all nodes on the local network segment, i.e. all nodes at most one hop away will see it, but it will not get forwarded through routers. That's generally how discovery of game servers on a LAN works.

I haven't heard about it working across customers on an ISP network, in fact I'd say that would be a pretty bad setup security-wise if each customer wasn't isolated to only talk between themselves and the ISP gateway. (Unless you were specifically addressing another customer's IP address.) Although maybe it could be possible for them to set up some kind of thing that recognizes the game discovery broadcasts and relays them to other customers' networks, but that would still be kind of weird.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

nielsm posted:

in fact I'd say that would be a pretty bad setup security-wise if each customer wasn't isolated to only talk between themselves and the ISP gateway. (Unless you were specifically addressing another customer's IP address.) Although maybe it could be possible for them to set up some kind of thing that recognizes the game discovery broadcasts and relays them to other customers' networks, but that would still be kind of weird.

I'd be completely unsurprised if whatever network conditions allowed this at the time have since been patched over, but I'm talking about the dark ages here. Security?

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club
Hey gang! I'm really frustrated in my progress working through this Python curriculum. I'm more than a month behind now; I anticipated I would be behind because I had some real life stuff going on, but I'm two weeks further behind that :(

I'm about ready to take the final, and I'm at this point reasonably confident I can pass it. My biggest hurdles have a lot to do with formatting, and dictionaries are still kind of frustrating me.

My last assignment before getting ready to take the practice assessment requires me to read a text file containing on alternating lines the number of seasons and then the name of a television show. So, like:

code:
20
Gunsmoke
30
The Simpsons
10
Will & Grace
14
Dallas
20
Law & Order
12
Murder, She Wrote
and I need to output:

code:
10: Will & Grace
12: Murder, She Wrote
14: Dallas
20: Gunsmoke; Law & Order
30: The Simpsons
And here is my awful code so far:

code:
newfile = open(input())
wordlist = newfile.readlines() #some people have been telling me not to use readlines, but it's part of the assignment
newfile.close()

thedict = {}
wordstring = ''
for line in wordlist:
    wordstring += line
    
for line in wordstring:
    splitstring = wordstring.split('\n')

splitstring.pop() # this is to get rid of an extra element in the list -- '' -- which I don't know how it got there but I am pretty sure it's a consequence of my code

while len(splitstring) != 0:
    thedict[splitstring[0]] = splitstring[1]
    del splitstring[0]
    del splitstring[0]
print(thedict)
I'm at the point in Python where I can get a lot of programs to function but in an incredibly messy way. I know it will benefit me to learn to be cleaner about it, but right now I'm struggling so much with just understanding how the language works. Further instructions will require me to sort the dictionary, but I'm not there yet. Right now my biggest problem is that some keys have multiple values. I can't for the life of me figure out how to update the key within the while loop in which all this is happening.

On a kind of related note, I'm wondering, how many of you learned code without any direct instruction whatsoever? This is so frustrating; I can't just raise my hand and ask a teacher if I'm stuck, you know. Often times I will spend hours working through something that could have been solved instantly by a teacher just telling me, "you need to make sure you do this..." or whatever. And while I find all your help invaluable, there is always hiccups and things lost in trying to negotiate teaching/learning in this manner; the code is messy, it's hard to articulate where my understanding of Python ends; I can't really ask these questions on stackoverflow because they're beginner level questions but are similar enough to questions that have already been answered that instead of walking me through it like I'm the beginner I am, they link me to another solved problem that is so far beyond where I'm at :mad:

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
You're reading in the lines from the file to a list of strings

Then joining all of them into one string

Then separating them into a list of strings, likely identical to the original list.

Consider operating on the original string list directly. Look at the functions that you can use with lists, can you just go through that original list?

If the lines contain '\n' can you use a trim function to remove them?

E: for help, used to was I used IRC for help. There's probably a slack channel that serves the same purpose.

Volmarias fucked around with this message at 23:58 on Mar 13, 2022

12 rats tied together
Sep 7, 2006

credburn posted:

Right now my biggest problem is that some keys have multiple values. I can't for the life of me figure out how to update the key within the while loop in which all this is happening.

If your keys have multiple values, you can consider using some kind of iterable sequence type (e.g. a list) as the value which will clean up your insertion logic quite a bit. Another thing I would recommend is, to start, any time you have to do a non-obvious thing to some input data to turn it into something useful, you should give it an explicit name. This really helps keep my head clear when I'm reading, and reasoning about, a complicated multi-step process. For example, consider:
Python code:
num_seasons = splitstring[0]
show_name = splitstring[1]

while some_condition:
    thedict[num_seasons] = show_name
You might even choose to put this logic into some kind of function, which you can put all the messiness behind and never have to think about again unless it errors.

credburn posted:

On a kind of related note, I'm wondering, how many of you learned code without any direct instruction whatsoever? This is so frustrating;
I've been there, it is very frustrating and I wish you luck. I think we're all trying to be helpful without giving you an exact answer, but I bet we'd all be happy to give you eaxct answers if you end up running out of time.

Computer viking
May 30, 2011
Now with less breakage.

Another little thing: pop() doesn't just remove the last value, it also returns it - so you can do x = stuff.pop() to get and delete in a single operation.


There are also some fancy ways to do this in very few lines - but I'm resisting the temptation to talk about them. Poke us after you're done if you'd like examples. :)

Sleepy Robot
Mar 24, 2006
instant constitutional scholar, just add astonomist
Someone with experience with vim and python, how should I approach this?

https://www.youtube.com/watch?v=-AZUIL1rY3U&t=230s

I want to write a python strategy to to vimspector test integration except with python instead of javascript. I already have debugpy working properly in nvim, but without test integration settings.

He mentions adding runtime arguments to the debug config file, but I have no idea how he's choosing them (and how they'd look for python). Also he's using a jest_strategy function to launch vimspector with the configuration with something that looks like a regex pattern for the test name. No idea how he's getting that.

RPATDO_LAMD
Mar 22, 2013

🐘🪠🍆

credburn posted:

Right now my biggest problem is that some keys have multiple values. I can't for the life of me figure out how to update the key within the while loop in which all this is happening.

When you have a problem like this, you should stop and consider how you're structuring your data.

It sounds like currently when you get input like "20: Gunsmoke" you are using 20 as the key and gunsmoke as the value. In a dictionary, each key has to be unique, but values can be duplicated as much as you want.

When you organize your data like this, you are basically implicitly saying "there can only be one show with 20 seasons, and it is gunsmoke". Then when you get "20: Law & Order" as input later, you get problems. On the other hand, if that code got "21: gunsmoke" as an input, it would be perfectly happy storing that since 21 is a new unique key.

The problem is that your key, "20" is not actually a unique identifier for the TV show. Multiple tv shows might have 20 seasons, and a show's season count might even change after the fact. So using the season count as your dictionary key causes problems.

To fix it you have to change how you organize your data. The simplest solution is to use the tv show as the key and the season count as the value in your dictionary -- there's only ever one instance of each tv show, and duplicate values are fine.

Another solution would be to use a list of pairs instead of a dictionary, like this:
code:
tv_show_pairs = []

my_first_pair = (20, "Gunsmoke")
tv_show_pairs.append(my_first_pair)

my_second_pair = (20, "Law & Order")
tv_show_pairs.append(my_second_pair)

for pair in tv_show_pairs:
	# do something
There is a lot decision making that goes into choosing between arrays vs dictionaries vs queues vs heaps etc at a higher level, but basically either should work just fine for this problem. Typically, arrays are easier when you have to iterate through and touch everything, but dictionaries are easier when you want to quickly find one specific entry since you can just look it up by its key.

edit: spoilered the "answer" since you might not want to just hear it

RPATDO_LAMD fucked around with this message at 03:40 on Mar 14, 2022

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club
Gosh, thanks again for all your help and patience walking this newb through some of this. I started over because everything was a mess. Much cleaner now, but I'm at another hiccup. My code is:

code:
newfile = open(input())
wordlist = newfile.readlines()
worddict = {}
n = 0
wordlist = [x.strip() for x in wordlist]
seasons = wordlist[0::2]
shows = wordlist[1::2]
for i in range(len(seasons)):
    if seasons[n] not in worddict:
        worddict[seasons[n]] = shows[n]
    n += 1

#this is where I was going to write a for loop for when a season in worddict
for reference, seasons = ['20', '30', '10', '14', '20', '12']
and shows = ['Gunsmoke', 'The Simpsons', 'Will & Grace', 'Dallas', 'Law & Order', 'Murder, She Wrote']

The assignment requires me to use the seasons as the keys, and the names of the shows as values. It expects a dictionary to output one of the keys with two values separated by a semicolon.

The part I'm stuck at now, for the key 20, it needs both Gunsmoke and Law & Order added to it. With my current code, it will only add new season/show key/value pairs. When I try to look up methods of adding a second value to an existing key, I'm inundated with (for me) very complex examples to merge and combine and do all kinds of things. I'm just trying to do this simple thing that I suspect takes all of one or two lines of code. Which again is to just add a new value to a key that already has a value, without overwriting said value.

edit also for reference:

This is what they are expecting the output to look like:

code:
10: Will & Grace
12: Murder, She Wrote
14: Dallas
20: Gunsmoke; Law & Order
30: The Simpsons

credburn fucked around with this message at 22:58 on Mar 15, 2022

ArcticZombie
Sep 15, 2010
Dictionaries can only have a single value per key. The type of the values in your dictionary are strings. You could replace the value with a new, longer, string that consisted of the previous value, some kind of separator, followed by the new show. But even easier, you could use a different type for the values in the dictionary, a type capable of storing multiple values, one that you can append to.

Edit: Having read what you wrote about the assignment more closely, it sounds like they expect you to actually do the first option.

ArcticZombie fucked around with this message at 22:41 on Mar 15, 2022

KillHour
Oct 28, 2007


Edit ^^ :argh:

I'm surprised they are making you use the number of seasons as keys since that's a dumb thing to do but the answer is to set each value to an empty array and then add each show to the correct array as you come across it.

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club

ArcticZombie posted:

Dictionaries can only have a single value per key.

Wait, what?

Gosh, I feel like I've wasted a dozen hours working through dictionary tutorials and brute forcing my way through assignments because I didn't understand a really fundamental aspect of dictionaries. I've been working all this time with the understanding that a key can have any number of values -- but I didn't realize that it's only by way of a list that it does so, that the list is itself the only value associated with the key -- am I understanding this correctly? gently caress, now that I know that I feel like I can get through so much of this.

Woebin
Feb 6, 2006

credburn posted:

Wait, what?

Gosh, I feel like I've wasted a dozen hours working through dictionary tutorials and brute forcing my way through assignments because I didn't understand a really fundamental aspect of dictionaries. I've been working all this time with the understanding that a key can have any number of values -- but I didn't realize that it's only by way of a list that it does so, that the list is itself the only value associated with the key -- am I understanding this correctly? gently caress, now that I know that I feel like I can get through so much of this.
Yeah, the idea behind a dictionary is basically that you can look up values within it based on their unique key, so having more than one value with the same key would defeat the purpose.

12 rats tied together
Sep 7, 2006

This would be one of those things you missed by not going to a formal school, yeah. Same thing happened to me when I was trying to teach myself from scratch, it's so easy to read "key value pair" and gloss over the ramifications of that.

Python calls them dictionaries but a more technically correct term could be "hash table" or "associative array". The way they work behind the scenes is complicated, but to super briefly summarize, your "key" is used as the input to a hashing function (link has a pretty good diagram, as well) which points to a particular location in memory. So long as you input the same key, you always get the same result, which is the exact location your data lives at.

This means that if you want to determine whether or not "Gunsmoke" is in your worddict, all you have to do is run "Gunsmoke" through the hashing function and check to see if anything is at the address that comes out. This is way faster than if you wanted to check to see if "Gunsmoke" was in wordlist, because you would have no choice but to check every item in it until you found "Gunsmoke", or found the end of the list.

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club
Hey gang!

Thanks again for your help. I'm still fighting my way through it and I reached another part I don't quite understand.

code:
n = 0
for i in range(len(seasons)):
    worddict.get(seasons[n]).append[shows[n]]
    n += 1
I set it up now to start with an empty list and then append everything to it. That way new entries can be alone in a list and if there are more than one, they share a list.

When I run it, I get a TypeError. So, it makes me think, that thing with get and append is where the problem is, but when I print just worddict.get(seasons[n]), without appending anything, it correctly returns an empty list. Please help me understand this better if this is not a correct read, but since an empty list is returned, isn't worddict.get(seasons[n]) effectively the same as an empty list, and therefore I feel I should be able to just append to it, but alas :(

credburn fucked around with this message at 03:16 on Mar 16, 2022

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
append is a function, but you're using square brackets after it as though it were a list you could index. That's where the type error is coming from.

You probably intended to call the function using parentheses instead.

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club
Oh, yes, god dammit you're right.

Sigh.

Thanks.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Let's say you work with people that insist on sending git-formatted patches through e-mail. Shouldn't everybody, like, explain the branch and commit to use as the base to apply the patch?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

credburn posted:

code:
n = 0
for i in range(len(seasons)):
    worddict.get(seasons[n]).append(shows[n])
    n += 1

It's been a while since I looked at python, but couldn't / shouldn't you just be using i as the index instead of creating a new variable to track and increment? That is,

code:
for i in range(len(seasons)):
    worddict.get(seasons[i]).append(shows[i])

Double edit: does python let you do


code:

worddict[seasons[i]].append(shows[i])

Or even better (and if it does, correctly, that's quite nice)


code:

worddict[seasons[i]] += shows[i]

Volmarias fucked around with this message at 07:51 on Mar 16, 2022

boofhead
Feb 18, 2021

credburn posted:

Oh, yes, god dammit you're right.

Sigh.

Thanks.

this is unrelated but-

you might be removing this from your code snippets to keep it simple, but you should also try to get into the habit of adding comments to your code, it can really help comprehension and debugging later (even when it's your own code, rather than someone else's)

for eg if your comment says "do Xa" but the code actually says "do Xb", you just saved yourself a lot of time going all sherlock holmes on your own typos and brainfarts, thinking "hm i wonder why i decided to do Xb" when it was a mistake all along

I also use a lot of psuedocode as comments when I'm mapping out something more complex so that I can make sure it makes sense before I start and get bogged down in details. Then it just becomes filling it in and working out the kinks, kinda like mapping out an essay at uni by writing a structure first with key sentences etc and fleshing it out with more detailed citations and so forth. It has helped me a lot to avoid coding myself into a corner and going "ahh poo poo I actually need to handle this here, not there"

E: this might be a little early for you, but in terms of dictionary values being more than just single strings: a dictionary key value can also be another dictionary with its own nested dictionaries, that's very common (you can look up JSON to see how large parts of the internet send complex data around). A dictionary key value can also be another function, rather than "dumb" data - so you could have a dictionary of functions that you look up by the key, which is used for more dynamic code and to help maintain readable code

boofhead fucked around with this message at 09:32 on Mar 16, 2022

Doc Neutral
Jan 31, 2014
Anyone who was some experience with UI/UX and more specifically usability testing might help me with this. I'm doing a small research project where I'll be doing some usability tests on a web application and was wondering what are good tools for remote usability testing (preferably unmoderated remote usability testing) that do not cost a lot of money, are free and/or have student licenses? Also what are good criteria for usability testing tools, like what features are must-haves and what features do you consider to be good to have but not absolutely necessary to do usability testing.

Thanks in advance!

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


boofhead posted:

you might be removing this from your code snippets to keep it simple, but you should also try to get into the habit of adding comments to your code, it can really help comprehension and debugging later (even when it's your own code, rather than someone else's)

Code you wrote sufficiently long ago is someone else's code.

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club

Volmarias posted:

It's been a while since I looked at python, but couldn't / shouldn't you just be using i as the index instead of creating a new variable to track and increment? That is,

code:
for i in range(len(seasons)):
    worddict.get(seasons[i]).append(shows[i])

Yessss i is a variable that increments every loop, of course I don't need a new one. Thanks for helping me clean this up.

boofhead
Feb 18, 2021

ultrafilter posted:

Code you wrote sufficiently long ago is someone else's code.

And that person is invariably the single worst coder you've ever heard of, thank god you would never make those sorts of mistakes again * groundhog day alarm clock rings *

Macichne Leainig
Jul 26, 2012

by VG
I think I'm an OK coder now but give it a couple months and future Protocol7 is gonna hate March 16th Protocol7.

killerwhat
May 13, 2010

credburn posted:

confusion

I am also a semi-noob, completed my coding bootcamp a year ago. I learned a lot from doing mini challenges on Code Wars. It's great because you can spend ages writing some awful, messy code to solve the puzzle, and then you get to see everyone else's answer. Normally someone's been ultra-clever and done it in one line. But other people will have done something readable. It's a good way to find out the most "correct" solution, but also maybe see some less basic methods used. Also, most puzzles are available in multiple languages, and there's a wide range of difficulty.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Protocol7 posted:

I think I'm an OK coder now but give it a couple months and future Protocol7 is gonna hate March 16th Protocol7.

This is the deep, dark truth of dev: you will come across something in six months time, say to yourself "what the gently caress, what loving idiot wrote this bizarre bullshit" and discover that the loving idiot was you all along. This happens to all of us, at all points in our careers, just embrace it.

KillHour
Oct 28, 2007


Excuse me - I've reached the point in my career where I realize I'm being a loving moron when I do it so my code is littered with "//I'm going to regret this" and "//if it's breaking this is probably why"

Macichne Leainig
Jul 26, 2012

by VG
It's more exciting if you're an amnesiac and the villain of the story was you all along!

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

KillHour posted:

Excuse me - I've reached the point in my career where I realize I'm being a loving moron when I do it so my code is littered with "//I'm going to regret this" and "//if it's breaking this is probably why"

Buddy, if you aren't writing "// this is horrible and I hate that I'm writing this but :techno:" at least once a month, you're probably in management.

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club

killerwhat posted:

I am also a semi-noob, completed my coding bootcamp a year ago. I learned a lot from doing mini challenges on Code Wars. It's great because you can spend ages writing some awful, messy code to solve the puzzle, and then you get to see everyone else's answer. Normally someone's been ultra-clever and done it in one line. But other people will have done something readable. It's a good way to find out the most "correct" solution, but also maybe see some less basic methods used. Also, most puzzles are available in multiple languages, and there's a wide range of difficulty.

Oh, thanks for this! I've been looking for something like this that motivates me better. Presently, my only real goal is LEARN THIS and that's a lot to take on.

Thanks again everyone for helping me with my dictionary assignment. I'm on minute 196 of this one goddamn assignment and I'm only a third finished. My next task goal here is to take any value that is a list with multiple values and separate the elements of said list with a semicolon. Once again I find myself perplexed as to why the output is what it is :(

(oh, this is Python, in case)

code:
for i in range(len(worddict)): # worddict being the dictionary
    if len(worddict.get(seasons[i])) > 1: # if any value within the dictionary contains more than one element
       '; '.join((worddict.get(seasons[i]))) # combine the elements, using a semicolon as separator


I don't get an error, but the list doesn't change. I guess this is related to converting the list to a string, but I want to combine all elements within the list. I thought maybe I could do that by

code:
worddict.get(seasons[i]) = ['; '.join((worddict.get(seasons[i])))]
But I get: SyntaxError: cannot assign to function call.

Also: I sure don't want to overly clutter the forums. Would it be helpful to repost the entire program, or is it sufficient to just post the part that's giving me trouble? I believe all the code that precedes the problematic code is functional and ought to be left alone ha

Anyway, presently the output looks like {'20': ['Gunsmoke', 'Law & Order'], ...} and I want it to look like{'20': ['Gunsmoke; Law & Order'], ...}

credburn fucked around with this message at 18:05 on Mar 16, 2022

Presto
Nov 22, 2002

Keep calm and Harry on.

ultrafilter posted:

Code you wrote sufficiently long ago is someone else's code.
And "sufficiently long ago" might be "this morning".

boofhead
Feb 18, 2021

credburn posted:

Oh, thanks for this! I've been looking for something like this that motivates me better. Presently, my only real goal is LEARN THIS and that's a lot to take on.

Thanks again everyone for helping me with my dictionary assignment. I'm on minute 196 of this one goddamn assignment and I'm only a third finished. My next task goal here is to take any value that is a list with multiple values and separate the elements of said list with a semicolon. Once again I find myself perplexed as to why the output is what it is :(

code:
for i in range(len(worddict)): # worddict being the dictionary
    if len(worddict.get(seasons[i])) > 1: # if any value within the dictionary contains more than one element
       '; '.join((worddict.get(seasons[i]))) # combine the elements, using a semicolon as separator


I don't get an error, but the list doesn't change. I guess this is related to converting the list to a string, but I want to combine all elements within the list. I thought maybe I could do that by

code:
worddict.get(seasons[i]) = ['; '.join((worddict.get(seasons[i])))]
But I get: SyntaxError: cannot assign to function call.

Also: I sure don't want to overly clutter the forums. Would it be helpful to repost the entire program, or is it sufficient to just post the part that's giving me trouble? I believe all the code that precedes the problematic code is functional and ought to be left alone ha

Anyway, presently the output looks like {'20': ['Gunsmoke', 'Law & Order'], ...} and I want it to look like{'20': ['Gunsmoke; Law & Order'], ...}

a few suggestions for how to approach this:

1. (not related to your problem) you essentially want to iterate through the key, value for each item in that worddict, right? this is a very common requirement - probably there's an easier way to do that directly rather than getting the len() and increasing the index each loop and referencing the same position in an array multiple times just to get the same value
2. (related to your problem) check more closely at what ";".join(array) and worddict.get(key) are doing.. are these methods that modify the original variable in place (less common in python), or do they return a value that you need to then do something else with? (e.g. save it to a new variable, or overwrite an existing variable with the value)
3. (not related to your problem) if you find yourself writing the same bit of code multiple times, it might be worth storing that in a variable (or, elsewhere, a function) that makes it easier to understand what's going on
4. (semi-related to your problem) every time you get an error from python that you don't understand, make a habit of googling it. python will tell you where the error occurs (i.e. which code is triggering it), and you can see if what you're trying to do makes sense

also, the syntax and intention on this line are making python very unhappy (and this is also part of why python is triggering an error):

code:
worddict.get(seasons[i]) = ['; '.join((worddict.get(seasons[i])))]
try to split it into multiple lines, step by step (e.g. value_one = "blah", value_two = "blee", value_three = value_one + value_two) and comment with what each line SHOULD be doing.. it might help

fe: also, if you find yourself banging your head against the wall, there are two common techniques to help combat this:
1. take a break and come back to it later -- get some fresh air, clean some dishes, have a shower or do some exercise. clear your head and break the loop of false/frustrated thinking
2. rubber ducky debugging -- go through the code line-by-line and explain verbally what it's actually doing (not what it SHOULD be doing) to a rubber ducky or an action figure or whatever object you have nearby

real edit: if you also just straight up want an example of code that should do what you want, let us know. generally it's better to figure it out yourself but sometimes life doesn't really give you the space to bang your head against the wall for hours on end, and god knows i wouldnt have gotten anywhere without stackoverflow etc

boofhead fucked around with this message at 18:22 on Mar 16, 2022

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Volmarias posted:

Buddy, if you aren't writing "// this is horrible and I hate that I'm writing this but :techno:" at least once a month, you're probably in management.

Yeah, but we do the same just in emails instead of code.

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

boofhead posted:

real edit: if you also just straight up want an example of code that should do what you want, let us know. generally it's better to figure it out yourself but sometimes life doesn't really give you the space to bang your head against the wall for hours on end, and god knows i wouldnt have gotten anywhere without stackoverflow etc

It's difficult to overstate the importance of sites like stack overflow. Putting the error message for something I don't understand into Google and examining the entrails results is something I do to this day. Just don't be that "oh hey I figured it out nevermind" post; tell everyone else / future you what the answer was!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply