Happy New Year, everybody!
I'm new in the Python List, new in Python world, and new in coding.
A few days (weeks?) ago, I faced a problem trying to write a program for an exercise. I asked for help and nobody answered.
In the meantime, I found a part of the solution, but a part still remains a mystery for me. Please run this small snippet, and help.
Thanks
a = [1, 2]
print()
print("a ==", a)
print("type(a) is", type(a))
b = a.append(3)
print("\nb =", "a.append(3)")
print("b ==", b)
print("type(b) is", type(b))
c = ['1', '2']
print("\nc ==", c)
print("type(c) is", type(c))
d = c.append('3')
print("\nd =", "c.append('3')")
print("d ==", d)
print("type(d) is", type(d))
"""
I mean: why b = a.append(something) is the None type, and how to make a new list
that contains all the items from a and some new items?
I wasn't able to solve it in a few hours :(
Now I know:
"""
crta = '='
print('\n', 4 * ' ', crta * (len('The solution:')), sep='')
print(3 * ' ', 'The solution:')
print(4 * ' ', crta * (len('The solution:')), sep='')
print('\nThe solution is the slice, an element of Python syntax that
allows')
print('to make a brand new copy of a list, or parts of a list.')
print('The slice actually copies the list\'s contents, not the list\'s name:')
print()
a = [1, 2]
print("a ==", a)
print("type(a) is", type(a))
b = a[:]
print("\nb = a[:]")
print("b ==", b)
b.append(3)
print("\nb =", "b.append(3)")
print("b ==", b)
print("type(b) is", type(b))
print("\na ==", a)
print('But I still don't know why "b = a.append(something)" is the None type.')
print('Is there anybody out there?!')
Happy New Year, everybody!
I'm new in the Python List, new in Python world, and new in coding.
A few days (weeks?) ago, I faced a problem trying to write a program for an exercise. I asked for help and nobody answered.
In the meantime, I found a part of the solution, but a part still remains a mystery for me. Please run this small snippet, and help.
Thanks
a = [1, 2]
print()
print("a ==", a)
print("type(a) is", type(a))
b = a.append(3)
print("\nb =", "a.append(3)")
print("b ==", b)
print("type(b) is", type(b))
c = ['1', '2']
print("\nc ==", c)
print("type(c) is", type(c))
d = c.append('3')
print("\nd =", "c.append('3')")
print("d ==", d)
print("type(d) is", type(d))
"""
I mean: why b = a.append(something) is the None type, and how to make a new list
that contains all the items from a and some new items?
I wasn't able to solve it in a few hours :(
Now I know:
"""
crta = '='
print('\n', 4 * ' ', crta * (len('The solution:')), sep='')
print(3 * ' ', 'The solution:')
print(4 * ' ', crta * (len('The solution:')), sep='')
print('\nThe solution is the slice, an element of Python syntax that
allows')
print('to make a brand new copy of a list, or parts of a list.')
print('The slice actually copies the list\'s contents, not the list\'s name:')
print()
a = [1, 2]
print("a ==", a)
print("type(a) is", type(a))
b = a[:]
print("\nb = a[:]")
print("b ==", b)
b.append(3)
print("\nb =", "b.append(3)")
print("b ==", b)
print("type(b) is", type(b))
print("\na ==", a)
print('But I still don't know why "b = a.append(something)" is the None type.')
print('Is there anybody out there?!')
A few days (weeks?) ago, I faced a problem trying to write a program for an exercise. I asked for help and nobody answered.
A few days (weeks?) ago, I faced a problem trying to write a program
for an exercise. I asked for help and nobody answered.
On 31/12/2022 18.45, Goran Ikac wrote:
...
A few days (weeks?) ago, I faced a problem trying to write a program
for an
exercise. I asked for help and nobody answered.
Looking back over the last six months of List-Archives, your name does
not appear against a single post. This may explain why "nobody answered".
However, ten hours after the above/first message, you posted again. This
time as "Thomas Passin".
That was followed an hour-or-so later, with a
reply-to-self saying: "Everyone's answer to date has been too
complicated", and then basically repeating the information previously-provided by a number of contributors.
It then goes on to talk about copying, sorting, adding, and even sets.
Much of which you had earlier said: "I know". Was there a further
question in there?
Which part of which answer did you find "too complicated"?
Did you try the experiments suggested, and read the references-provided?
Please ask a further question detailing what you have understood, and
what is still mystifying. Folk here endeavor to be helpful (see also,
earlier reference to the Python-Tutor list).
When asking a question here, please try to reduce the problem to its
simplest form, so that you're not asking volunteers to read
multiple-screens of irrelevant code. It will help to ask one question at
a time, or to carefully separate multiple questions.
Yes, this can be difficult when one is learning. That said, we all
started somewhere and are happy to help you to become a valued colleague!
And, of course, we had the philosophical question of why the feature was designed to not return anything ... rather than return the changed
object.
And, of course, we had the philosophical question of why the feature
was designed to not return anything ... rather than return the changed object.
Had a language like that been created today, I wonder if some designs might have looked a bit different so that some functions could be called with optional arguments that specified what the user wanted returned.
Had a language like that been created today, I wonder if some designsreturned.
might have looked a bit different so that some functions could be
called with optional arguments that specified what the user wanted
Chris,
There is much to say about consistent behavior as compared to flexibility
and convenience.
I have seen other languages provide functions for example, where the result can vary and often cause confusion. R had a function that would sometimes notice the result could be simplified and return that. Guess what? It caused lots of problems and an option was added that said it should NOT simplify
and always return the same kind of thing.
As a dumb example, what does a simple function like max() return if fed just integers, just floating point or a combination of both? It seems to return whatever type the maximum indicates. But it also accepts characters and
sorts them appropriately returning type 'str' and probably accepts and returns all kinds of objects if you specify a key function.
Is that so much different than we are discussing in that there isn't any absolute consistency and things can go various ways in terms of return
value? Heck, I can even make max() return None!
Agreed, there are lots of pro/con arguments and the feature is what it is historically and not trivial to change. Inline changes to an object make sense to just be done "silently" and if there are errors, they propagate the usual way.
As Guido was a major influence at that time, one view was seen as more important and prevailed.
Had a language like that been created today, I wonder if some designs might have looked a bit different so that some functions could be called with optional arguments that specified what the user wanted returned.
In particular, besides a function where you add a value returning nothing/None, there may be room for other choices and any choice hard-wired in would eleicit complaints from others.
lst.add("Value")
could also return one of several other things such as a pointer to the upgraded object but also of a pointer to the object as it looked before the change (not a serious proposal) or a True/False value specifying if the change was able to be completed (such as running out of memory, or the addition not being something you can put in the object) or even return what was added or how many objects are now in the object at the top level, or how many times the method was called so far!
I suspect, at the expense of some overhead, you could just add an argument
to many kinds of methods or even functions such as returning='option' that guides what you want returned, with the default often being what Guido and others currently have set.
Python already allows functions to return anything they feel like, so this probably would not break many things.
Of course there are other paths in that direction, such as setting an attribute of the list/object first that affects how things get returned but that seems more cumbersome and makes all kinds of errors more likely. Still, that is a path often used by some Python modules where objects are created and then tweaked to behave in various ways when later methods are invoked.
But is any of it needed? The current system generally works fine and we have seen many ways to get other results without tampering with the current implementation.
This may be yet another example of people who come to python with pre-existing bias, such as insisting it work like another language they have used, or wanting the computer to do what they MEANT rather than what they explicitly or implicitly programmed!
-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Greg Ewing
Sent: Saturday, December 31, 2022 7:21 PM
To: python-list@python.org
Subject: Re: NoneType List
On 1/01/23 11:36 am, avi.e.gross@gmail.com wrote:
And, of course, we had the philosophical question of why the feature
was designed to not return anything ... rather than return the changed
object.
My understanding is that Guido designed it that way to keep a clear
5x = 1
y = (x := 5)
y
21z = (x := x * 2) + (x := x + 1)
z
11x
Happy New Year, everybody!
I'm new in the Python List, new in Python world, and new in coding.
A few days (weeks?) ago, I faced a problem trying to write a program
for an exercise. I asked for help and nobody answered.
In the meantime, I found a part of the solution, but a part still
remains a mystery for me. Please run this small snippet, and help.
Thanks
a = [1, 2]
print()
print("a ==", a)
print("type(a) is", type(a))
b = a.append(3)
print("\nb =", "a.append(3)")
print("b ==", b)
print("type(b) is", type(b))
c = ['1', '2']
print("\nc ==", c)
print("type(c) is", type(c))
d = c.append('3')
print("\nd =", "c.append('3')")
print("d ==", d)
print("type(d) is", type(d))
"""
I mean: why b = a.append(something) is the None type, and how to make
a new list that contains all the items from a and some new items?
I wasn't able to solve it in a few hours :( Now I know:
"""
crta = '='
print('\n', 4 * ' ', crta * (len('The solution:')), sep='')
print(3 * ' ', 'The solution:')
print(4 * ' ', crta * (len('The solution:')), sep='') print('\nThe
solution is the slice, an element of Python syntax that
allows')
print('to make a brand new copy of a list, or parts of a list.')
print('The slice actually copies the list\'s contents, not the list\'s name:')
print()
a = [1, 2]
print("a ==", a)
print("type(a) is", type(a))
b = a[:]
print("\nb = a[:]")
print("b ==", b)
b.append(3)
print("\nb =", "b.append(3)")
print("b ==", b)
print("type(b) is", type(b))
print("\na ==", a)
print('But I still don't know why "b = a.append(something)" is the
None
type.')
print('Is there anybody out there?!')
Happy New Year, everybody!
I'm new in the Python List, new in Python world, and new in coding.
A few days (weeks?) ago, I faced a problem trying to write a program
for an exercise. I asked for help and nobody answered.
In the meantime, I found a part of the solution, but a part still
remains a mystery for me. Please run this small snippet, and help.
Thanks
a = [1, 2]
print()
print("a ==", a)
print("type(a) is", type(a))
b = a.append(3)
print("\nb =", "a.append(3)")
print("b ==", b)
print("type(b) is", type(b))
c = ['1', '2']
print("\nc ==", c)
print("type(c) is", type(c))
d = c.append('3')
print("\nd =", "c.append('3')")
print("d ==", d)
print("type(d) is", type(d))
"""
I mean: why b = a.append(something) is the None type, and how to make
a new list that contains all the items from a and some new items?
I wasn't able to solve it in a few hours :( Now I know:
"""
crta = '='
print('\n', 4 * ' ', crta * (len('The solution:')), sep='')
print(3 * ' ', 'The solution:')
print(4 * ' ', crta * (len('The solution:')), sep='') print('\nThe
solution is the slice, an element of Python syntax that
allows')
print('to make a brand new copy of a list, or parts of a list.')
print('The slice actually copies the list\'s contents, not the list\'s name:')
print()
a = [1, 2]
print("a ==", a)
print("type(a) is", type(a))
b = a[:]
print("\nb = a[:]")
print("b ==", b)
b.append(3)
print("\nb =", "b.append(3)")
print("b ==", b)
print("type(b) is", type(b))
print("\na ==", a)
print('But I still don't know why "b = a.append(something)" is the
None
type.')
print('Is there anybody out there?!')
A few days (weeks?) ago, I faced a problem trying to write a program
for an exercise. I asked for help and nobody answered.
A few days (weeks?) ago, I faced a problem trying to write a program
for an exercise. I asked for help and nobody answered.
On 31/12/2022 18.45, Goran Ikac wrote:
...
A few days (weeks?) ago, I faced a problem trying to write a program
for an exercise. I asked for help and nobody answered.
Looking back over the last six months of List-Archives, your name does
not appear against a single post. This may explain why "nobody answered".
However, ten hours after the above/first message, you posted again.
This time as "Thomas Passin".
That was followed an hour-or-so later, with a reply-to-self saying: "Everyone's answer to date has been too complicated", and then
basically repeating the information previously-provided by a number of contributors.
It then goes on to talk about copying, sorting, adding, and even sets.
Much of which you had earlier said: "I know". Was there a further
question in there?
Which part of which answer did you find "too complicated"?
Did you try the experiments suggested, and read the references-provided?
Please ask a further question detailing what you have understood, and
what is still mystifying. Folk here endeavor to be helpful (see also,
earlier reference to the Python-Tutor list).
When asking a question here, please try to reduce the problem to its
simplest form, so that you're not asking volunteers to read
multiple-screens of irrelevant code. It will help to ask one question
at a time, or to carefully separate multiple questions.
Yes, this can be difficult when one is learning. That said, we all
started somewhere and are happy to help you to become a valued colleague!
And, of course, we had the philosophical question of why the feature
was designed to not return anything ... rather than return the changed object.
And, of course, we had the philosophical question of why the feature
was designed to not return anything ... rather than return the changed object.
Had a language like that been created today, I wonder if some designsreturned.
might have looked a bit different so that some functions could be
called with optional arguments that specified what the user wanted
Had a language like that been created today, I wonder if some designsreturned.
might have looked a bit different so that some functions could be
called with optional arguments that specified what the user wanted
Chris,
There is much to say about consistent behavior as compared to
flexibility and convenience.
I have seen other languages provide functions for example, where the
result can vary and often cause confusion. R had a function that would sometimes notice the result could be simplified and return that. Guess
what? It caused lots of problems and an option was added that said it
should NOT simplify and always return the same kind of thing.
As a dumb example, what does a simple function like max() return ifkey function.
fed just integers, just floating point or a combination of both? It
seems to return whatever type the maximum indicates. But it also
accepts characters and sorts them appropriately returning type 'str'
and probably accepts and returns all kinds of objects if you specify a
Is that so much different than we are discussing in that there isn't
any absolute consistency and things can go various ways in terms of
return value? Heck, I can even make max() return None!
Agreed, there are lots of pro/con arguments and the feature is what itreturned.
is historically and not trivial to change. Inline changes to an object
make sense to just be done "silently" and if there are errors, they
propagate the usual way.
As Guido was a major influence at that time, one view was seen as
more important and prevailed.
Had a language like that been created today, I wonder if some designs
might have looked a bit different so that some functions could be
called with optional arguments that specified what the user wanted
In particular, besides a function where you add a value returning nothing/None, there may be room for other choices and any choicefar!
hard-wired in would eleicit complaints from others.
lst.add("Value")
could also return one of several other things such as a pointer to the upgraded object but also of a pointer to the object as it looked
before the change (not a serious proposal) or a True/False value
specifying if the change was able to be completed (such as running out
of memory, or the addition not being something you can put in the
object) or even return what was added or how many objects are now in
the object at the top level, or how many times the method was called so
I suspect, at the expense of some overhead, you could just add an
argument to many kinds of methods or even functions such as returning='option' that guides what you want returned, with the
default often being what Guido and others currently have set.
Python already allows functions to return anything they feel like, so
this probably would not break many things.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 76:54:23 |
Calls: | 6,716 |
Files: | 12,247 |
Messages: | 5,357,582 |