+ 1

[Solved] About List Comp and error after running a code copied from another site

https://code.sololearn.com/c5jRVvwVFhyX/?ref=app This code is from: https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-list-comprehension/ My questions: 1) Why is there a syntax error? https://pythonguides.com/syntaxerror-invalid-character-in-identifier-python3/#:~:text=In%20python%2C%20if%20you%20run,formatted%20code%20from%20any%20website. Here it says: "In python, if you run the code then you may get python invalid character in identifier error because of some character in the middle of a Python variable name, function. Or most commonly we get this error because you have copied some formatted code from any website." I guess the latter's the reason, but why? 2) On the Geeks site, the output is: [++++[+10, 40, 70], [20, 50, 80], [30, 60, 90]] Why are there all these plusses? Thank you all in advance for your time spent reading this and/or responding.

25th Mar 2022, 5:28 PM
Korkunç el Gato
Korkunç el Gato - avatar
12 Respostas
+ 2
Click on the end of the line. Then remove everything that is not a visible character Do the same for all the seemingly blank spaces in-between.
25th Mar 2022, 6:26 PM
Lisa
Lisa - avatar
+ 2
Simply read the error message. It hints at the line with the problematic characters https://code.sololearn.com/cF8OQQUXoqvI/?ref=app
25th Mar 2022, 6:34 PM
Lisa
Lisa - avatar
26th Mar 2022, 7:02 AM
HungryTradie
HungryTradie - avatar
+ 1
You seem to have several special characters that cannot be displayed in the script. Remove them...
25th Mar 2022, 6:01 PM
Lisa
Lisa - avatar
+ 1
"Cannot be displayed" == "invisible" character
25th Mar 2022, 6:20 PM
Lisa
Lisa - avatar
+ 1
That could be an error on their site: The text says "Example 2: Display even elements from a list of random numbers." But the code is about transposing a matrix. Maybe they just added the wrong code example (and a wrong output example)?
25th Mar 2022, 6:47 PM
Lisa
Lisa - avatar
+ 1
HungryTradie Dear HungryTradie, to the rescue, as per my experience :-) I am grateful for the link, I will now set out to read it. Later Edit: My original question asked three whys: why the error, why the invisible "format", why the output with the + signs. There's a link in the website whose link you provided, with the hyperlinked text "HERE". Upon clicking it, I was redirected to another SO page, https://stackoverflow.com/questions/689185/json-decode-returns-null-after-webservice-call/689237#689237, where I was able to see why these invisible characters are in the script. It's certainly way beyond my knowledge right now, but it's about Unicode, UTF, ASCII and such. It's important for a beginner to get to know about the reasons why a certain type of exception is thrown. I've merged my pre-link-visit and post-link-visit posts into one to clear up the space. Thank you. Your link answers my question.
26th Mar 2022, 11:39 AM
Korkunç el Gato
Korkunç el Gato - avatar
0
Lisa : But there's nothing wrong with the identifier's name. I deleted extra space in the matrix and nothing changed. What else is there? Just like the part I quoted from the other site says, I guess it is due to "formatted code". Is it something invisible?
25th Mar 2022, 6:15 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
Lisa :You said "in the script". You also said "remove". I cannot remove what I cannot see? It's not my code to begin with? I was trying to understand if it meant "it cannot be rendered/read" or "cannot be seen". But thanks anyways...
25th Mar 2022, 6:25 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
No change... Thank you for clarifying btw. I'll completely copy it by printing myself. Assuming this is some preventive measure or something, then, and not about the code. Anyone having any idea about the plusses?
25th Mar 2022, 6:32 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
Lisa It runs now, although I haven't made any changes to the last one. I had saved it before running it, too. Weird. The first thing I played with was the 5th line, I deleted the spaces between the matrix elements but it threw an error then, too. So it was either the 5th line but in the space outside the matrix or the end of the line. I cannot tell because it is only now that it runs smoothly. I also got a disconnection notification, which might be why there was a delay. Still, though, those plusses, if I may (they aren't displayed in SL editor's output)
25th Mar 2022, 6:42 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
Lisa Lol yeah, may well be but the output seemed to be compatible with the script. But I take it that it's not normal, so thank you.
25th Mar 2022, 6:54 PM
Korkunç el Gato
Korkunç el Gato - avatar