Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Ok am bad at this, but isn't there an error in second loop? Since b is not a list in second loop?
-
[[1],...,[9]] twice
But really it ain't that clear. At a quick glance I'd probably have said it would yield an undefined error for b. -
olback107946yI'm not a python dev but isn't the output the same? b = [i] would make b an array with index 0 = i, right? b[0] = i would also set index 0 = i, yes? I'm probably wrong though. 🤷♂️
-
@telephantasm no because of those friend is in final year of graduation, and I was gave her tips on what topics to study to get placed in a good company.
-
The output wouldn't be an error or [[1],...[9]] twice.
Correct output is:
1-9
9.. 9 (9 times) -
Wow, I can write bad code that confuses people too. I thought I was the only one! We're so much better than those people who think they know what they're doing.
-
Everyone above is wrong. The actual output is: "how are you any productive with that much transparency on your terminal window?"
-
@BugsBuggy
I ran this program in 3.7 shell and it gave the same answer as you wrote with brackets ( [[1]..[9]] and [9]...[9] )
I guess its maybe because variables created inside the loop also have the same scope as the ones outside? -
olback107946ySo this works because b is hoisted to the top for some reason. Removing the first for-loop breaks the whole thing. Also adding print(c) in the second loop gives you this (see image) which explains the output and somewhat weird(?) behavior.
-
Is it because each element of c is a reference to b? Which is constantly being changed and thus will reflect the final version of b?! Fuck!
I have encountered this a million times, and Everytime I struggle to understand it at all for like 20 min!
Maybe if this was in c and I could tell if it was a pointer this would make some goddamn sense! -
@dontPanic I'm not good with linux terminal sometimee, so with transparency, I can see the commands from the docs I have opened in browser below the terminal :P
-
@everyone the reason that it depresses me is because everyone has been using the concept in some way or the other, like calling function on an object without assigning any return value to any variable. Eg:
```
x=SomeRandomObject
random_function(x) #changes values in x
print x
#TADA: x gets changed here as well
```
A couple of my friends failed to answer the correct output for this.
I have been working on Python since a month, they have, for months and years.
I am so depressed right now.
rant