Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103708 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2016-02-29 05:45 -0800 |
| Last post | 2016-02-29 09:48 -0500 |
| Articles | 10 — 6 participants |
Back to article view | Back to comp.lang.python
General computer language, syntax question. jonas.thornvall@gmail.com - 2016-02-29 05:45 -0800
Re: General computer language, syntax question. jonas.thornvall@gmail.com - 2016-02-29 05:56 -0800
Re: General computer language, syntax question. jonas.thornvall@gmail.com - 2016-02-29 06:05 -0800
Re: General computer language, syntax question. Joel Goldstick <joel.goldstick@gmail.com> - 2016-02-29 09:38 -0500
Re: General computer language, syntax question. Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-29 07:54 -0700
Re: General computer language, syntax question. Steven D'Aprano <steve@pearwood.info> - 2016-03-01 22:42 +1100
Re: General computer language, syntax question. Joel Goldstick <joel.goldstick@gmail.com> - 2016-02-29 08:55 -0500
Re: General computer language, syntax question. MRAB <python@mrabarnett.plus.com> - 2016-02-29 14:07 +0000
Re: General computer language, syntax question. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-29 14:39 +0000
Re: General computer language, syntax question. Joel Goldstick <joel.goldstick@gmail.com> - 2016-02-29 09:48 -0500
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-02-29 05:45 -0800 |
| Subject | General computer language, syntax question. |
| Message-ID | <5b619ffa-aae6-4fa8-9f62-58532668ec93@googlegroups.com> |
I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features
"Actually i program in javascript" but the problem seem general for all programming languages including Pyhton.
For a beautiful solution it would require "If in list/array return boolean" "If not in list/array return boolean".
But there is no such feature Python nor Javascript, so instead i set boolean value "inlist" to false and loop thru, to see if it is already in list. If not it is added to list.
So if the current node i generate links for is x and i try to generate a link to node z, and z's links exhausted i will add it to exhausted list.
And if there is node-x exhausted entries in list, well then script should break because it will lock into a cycle. The cyclic lockup is due to only a subset of the networks on the form (links*deep)+1=nodes is possible.
So what i need is to know howto write "if list/array ***empty*** do {something}"
I sure know howto check if an array have 1 element 2,3,4 but how do you check for empty.
I think it is crazy that you can not do general comparissons of the type
If in list/array
If not in list/array
But it is even more crazy that you can not check if list/array is empty, that is just madness.
[toc] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-02-29 05:56 -0800 |
| Message-ID | <f6536a77-6f32-4af7-bf2d-126b92ec5649@googlegroups.com> |
| In reply to | #103708 |
Den måndag 29 februari 2016 kl. 14:45:37 UTC+1 skrev jonas.t...@gmail.com:
> I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features
>
> "Actually i program in javascript" but the problem seem general for all programming languages including Pyhton.
>
> For a beautiful solution it would require "If in list/array return boolean" "If not in list/array return boolean".
>
> But there is no such feature Python nor Javascript, so instead i set boolean value "inlist" to false and loop thru, to see if it is already in list. If not it is added to list.
>
> So if the current node i generate links for is x and i try to generate a link to node z, and z's links exhausted i will add it to exhausted list.
>
> And if there is node-x exhausted entries in list, well then script should break because it will lock into a cycle. The cyclic lockup is due to only a subset of the networks on the form (links*deep)+1=nodes is possible.
>
> So what i need is to know howto write "if list/array ***empty*** do {something}"
>
> I sure know howto check if an array have 1 element 2,3,4 but how do you check for empty.
>
> I think it is crazy that you can not do general comparissons of the type
> If in list/array
> If not in list/array
>
> But it is even more crazy that you can not check if list/array is empty, that is just madness.
I mean for for example Javascript
if (typeof array[index] !== 'undefined' && array[index] !== null) {
or this one
if (array[index] != null) {
I mean how do they come up with such convoluted syntax, do they pull it out of ass? Well one can always say it is needed because undefined not equal to null.
But would not if (array[index]==empty) suffice and be alot clearer?
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-02-29 06:05 -0800 |
| Message-ID | <b03495c3-bef8-4060-be15-bf96cedf072b@googlegroups.com> |
| In reply to | #103710 |
Den måndag 29 februari 2016 kl. 14:57:04 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 29 februari 2016 kl. 14:45:37 UTC+1 skrev jonas.t...@gmail.com:
> > I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features
> >
> > "Actually i program in javascript" but the problem seem general for all programming languages including Pyhton.
> >
> > For a beautiful solution it would require "If in list/array return boolean" "If not in list/array return boolean".
> >
> > But there is no such feature Python nor Javascript, so instead i set boolean value "inlist" to false and loop thru, to see if it is already in list. If not it is added to list.
> >
> > So if the current node i generate links for is x and i try to generate a link to node z, and z's links exhausted i will add it to exhausted list.
> >
> > And if there is node-x exhausted entries in list, well then script should break because it will lock into a cycle. The cyclic lockup is due to only a subset of the networks on the form (links*deep)+1=nodes is possible.
> >
> > So what i need is to know howto write "if list/array ***empty*** do {something}"
> >
> > I sure know howto check if an array have 1 element 2,3,4 but how do you check for empty.
> >
> > I think it is crazy that you can not do general comparissons of the type
> > If in list/array
> > If not in list/array
> >
> > But it is even more crazy that you can not check if list/array is empty, that is just madness.
>
> I mean for for example Javascript
> if (typeof array[index] !== 'undefined' && array[index] !== null) {
> or this one
> if (array[index] != null) {
>
> I mean how do they come up with such convoluted syntax, do they pull it out of ass? Well one can always say it is needed because undefined not equal to null.
>
> But would not if (array[index]==empty) suffice and be alot clearer?
Sorry but would not if (array==empty) suffice and be alot clearer?
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2016-02-29 09:38 -0500 |
| Message-ID | <mailman.10.1456756733.20602.python-list@python.org> |
| In reply to | #103712 |
On Mon, Feb 29, 2016 at 9:05 AM, <jonas.thornvall@gmail.com> wrote:
> Den måndag 29 februari 2016 kl. 14:57:04 UTC+1 skrev jonas.t...@gmail.com:
> > Den måndag 29 februari 2016 kl. 14:45:37 UTC+1 skrev
> jonas.t...@gmail.com:
> > > I have a problem programming uniform networks, "x nodes with y links"
> that turn out to be really hairy to solve for me and i feel i really lack
> the programming features
> > >
> > > "Actually i program in javascript" but the problem seem general for
> all programming languages including Pyhton.
> > >
> > > For a beautiful solution it would require "If in list/array return
> boolean" "If not in list/array return boolean".
> > >
> > > But there is no such feature Python nor Javascript, so instead i set
> boolean value "inlist" to false and loop thru, to see if it is already in
> list. If not it is added to list.
> > >
> > > So if the current node i generate links for is x and i try to generate
> a link to node z, and z's links exhausted i will add it to exhausted list.
> > >
> > > And if there is node-x exhausted entries in list, well then script
> should break because it will lock into a cycle. The cyclic lockup is due to
> only a subset of the networks on the form (links*deep)+1=nodes is possible.
> > >
> > > So what i need is to know howto write "if list/array ***empty*** do
> {something}"
> > >
> > > I sure know howto check if an array have 1 element 2,3,4 but how do
> you check for empty.
> > >
> > > I think it is crazy that you can not do general comparissons of the
> type
> > > If in list/array
> > > If not in list/array
> > >
> > > But it is even more crazy that you can not check if list/array is
> empty, that is just madness.
> >
> > I mean for for example Javascript
> > if (typeof array[index] !== 'undefined' && array[index] !== null) {
> > or this one
> > if (array[index] != null) {
> >
> > I mean how do they come up with such convoluted syntax, do they pull it
> out of ass? Well one can always say it is needed because undefined not
> equal to null.
> >
> > But would not if (array[index]==empty) suffice and be alot clearer?
>
> Sorry but would not if (array==empty) suffice and be alot clearer?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
You might have better luck on a javascript mailing list. Not sure crazy,
madness, ass are descriptive to your problems
--
Joel Goldstick
http://joelgoldstick.com/ <http://joelgoldstick.com/stats/birthdays>
http://cc-baseballstats.info/
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2016-02-29 07:54 -0700 |
| Message-ID | <mailman.13.1456757647.20602.python-list@python.org> |
| In reply to | #103712 |
On Feb 29, 2016 7:11 AM, <jonas.thornvall@gmail.com> wrote: > > Sorry but would not if (array==empty) suffice and be alot clearer? In Python, you can just do "if len(array) == 0" or "if not array". In JavaScript you have "if (array.length === 0)". Is there some problem with that? I would prefer this over your suggestion since it doesn't require some variable named "empty" to have a sensible value set. On the container test, as others pointed out, Python has the "in" operator. JavaScript has a draft Array.prototype.includes method, but it doesn't have broad cross-browser support yet.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2016-03-01 22:42 +1100 |
| Message-ID | <56d5801f$0$1620$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #103710 |
On Tue, 1 Mar 2016 12:56 am, jonas.thornvall@gmail.com wrote:
> I mean for for example Javascript
Jonas, this is a Python forum. If we thought Javascript was a beautiful and
well-designed language, we're be on a Javascript forum, complaining about
Python.
> if (typeof array[index] !== 'undefined' && array[index] !== null) {
> or this one
> if (array[index] != null) {
>
> I mean how do they come up with such convoluted syntax, do they pull it
> out of ass?
Probably. I don't know Javascript very well. It is possible that your
statements about Javascript are as misinformed as your statements about
Python.
In Python, you certainly can do membership testing of a list:
py> alist = ["ab", "cd", "ef", "gh"]
py> "ef" in alist
True
py> "xy" in alist
False
and you can also test for empty lists just as easily:
py> if alist:
... print("not empty")
... else:
... print("empty")
...
not empty
py> blist = []
py> if blist:
... print("not empty")
... else:
... print("empty")
...
empty
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2016-02-29 08:55 -0500 |
| Message-ID | <mailman.8.1456754608.20602.python-list@python.org> |
| In reply to | #103708 |
On Mon, Feb 29, 2016 at 8:45 AM, <jonas.thornvall@gmail.com> wrote:
> I have a problem programming uniform networks, "x nodes with y links" that
> turn out to be really hairy to solve for me and i feel i really lack the
> programming features
>
> "Actually i program in javascript" but the problem seem general for all
> programming languages including Pyhton.
>
> For a beautiful solution it would require "If in list/array return
> boolean" "If not in list/array return boolean".
>
> But there is no such feature Python nor Javascript, so instead i set
> boolean value "inlist" to false and loop thru, to see if it is already in
> list. If not it is added to list.
>
> So if the current node i generate links for is x and i try to generate a
> link to node z, and z's links exhausted i will add it to exhausted list.
>
> And if there is node-x exhausted entries in list, well then script should
> break because it will lock into a cycle. The cyclic lockup is due to only a
> subset of the networks on the form (links*deep)+1=nodes is possible.
>
> So what i need is to know howto write "if list/array ***empty*** do
> {something}"
>
> I sure know howto check if an array have 1 element 2,3,4 but how do you
> check for empty.
>
> I think it is crazy that you can not do general comparissons of the type
> If in list/array
> If not in list/array
>
> But it is even more crazy that you can not check if list/array is empty,
> that is just madness.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>>> l = [1,2,3,4]
>>> if 1 in l:
... print 1
...
1
>>> if 6 in l:
... print 1
...
>>>
>>> l = []
>>> if len(l) == 0:
... print 'empty'
...
empty
--
Joel Goldstick
http://joelgoldstick.com/ <http://joelgoldstick.com/stats/birthdays>
http://cc-baseballstats.info/
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2016-02-29 14:07 +0000 |
| Message-ID | <mailman.9.1456754835.20602.python-list@python.org> |
| In reply to | #103708 |
On 2016-02-29 13:45, jonas.thornvall@gmail.com wrote:
> I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features
>
> "Actually i program in javascript" but the problem seem general for all programming languages including Pyhton.
>
> For a beautiful solution it would require "If in list/array return boolean" "If not in list/array return boolean".
>
> But there is no such feature Python nor Javascript, so instead i set boolean value "inlist" to false and loop thru, to see if it is already in list. If not it is added to list.
>
> So if the current node i generate links for is x and i try to generate a link to node z, and z's links exhausted i will add it to exhausted list.
>
> And if there is node-x exhausted entries in list, well then script should break because it will lock into a cycle. The cyclic lockup is due to only a subset of the networks on the form (links*deep)+1=nodes is possible.
>
> So what i need is to know howto write "if list/array ***empty*** do {something}"
>
> I sure know howto check if an array have 1 element 2,3,4 but how do you check for empty.
>
> I think it is crazy that you can not do general comparissons of the type
> If in list/array
> If not in list/array
>
> But it is even more crazy that you can not check if list/array is empty, that is just madness.
>
Does this help?
>>> items = ['a', 'b', 'c', 'd', 'e']
>>> 'c' in items
True
>>> 'f' in items
False
>>> len(items)
5
>>> len([])
0
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2016-02-29 14:39 +0000 |
| Message-ID | <mailman.11.1456756830.20602.python-list@python.org> |
| In reply to | #103708 |
On 29/02/2016 13:45, jonas.thornvall@gmail.com wrote:
> I have a problem programming uniform networks, "x nodes with y links" that turn out to be really hairy to solve for me and i feel i really lack the programming features
>
> "Actually i program in javascript" but the problem seem general for all programming languages including Pyhton.
>
> For a beautiful solution it would require "If in list/array return boolean" "If not in list/array return boolean".
>
> But there is no such feature Python nor Javascript, so instead i set boolean value "inlist" to false and loop thru, to see if it is already in list. If not it is added to list.
>
> So if the current node i generate links for is x and i try to generate a link to node z, and z's links exhausted i will add it to exhausted list.
>
> And if there is node-x exhausted entries in list, well then script should break because it will lock into a cycle. The cyclic lockup is due to only a subset of the networks on the form (links*deep)+1=nodes is possible.
>
> So what i need is to know howto write "if list/array ***empty*** do {something}"
>
> I sure know howto check if an array have 1 element 2,3,4 but how do you check for empty.
>
> I think it is crazy that you can not do general comparissons of the type
> If in list/array
> If not in list/array
>
> But it is even more crazy that you can not check if list/array is empty, that is just madness.
>
Please see
https://docs.python.org/3/library/stdtypes.html#truth-value-testing
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2016-02-29 09:48 -0500 |
| Message-ID | <mailman.14.1456757689.20602.python-list@python.org> |
| In reply to | #103708 |
On Mon, Feb 29, 2016 at 9:39 AM, Mark Lawrence <breamoreboy@yahoo.co.uk>
wrote:
> On 29/02/2016 13:45, jonas.thornvall@gmail.com wrote:
>
>> I have a problem programming uniform networks, "x nodes with y links"
>> that turn out to be really hairy to solve for me and i feel i really lack
>> the programming features
>>
>> "Actually i program in javascript" but the problem seem general for all
>> programming languages including Pyhton.
>>
>> For a beautiful solution it would require "If in list/array return
>> boolean" "If not in list/array return boolean".
>>
>> But there is no such feature Python nor Javascript, so instead i set
>> boolean value "inlist" to false and loop thru, to see if it is already in
>> list. If not it is added to list.
>>
>> So if the current node i generate links for is x and i try to generate a
>> link to node z, and z's links exhausted i will add it to exhausted list.
>>
>> And if there is node-x exhausted entries in list, well then script should
>> break because it will lock into a cycle. The cyclic lockup is due to only a
>> subset of the networks on the form (links*deep)+1=nodes is possible.
>>
>> So what i need is to know howto write "if list/array ***empty*** do
>> {something}"
>>
>> I sure know howto check if an array have 1 element 2,3,4 but how do you
>> check for empty.
>>
>> I think it is crazy that you can not do general comparissons of the type
>> If in list/array
>> If not in list/array
>>
>> But it is even more crazy that you can not check if list/array is empty,
>> that is just madness.
>>
>>
> Please see
> https://docs.python.org/3/library/stdtypes.html#truth-value-testing
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>>> l = []
>>> l
[]
>>> if l:
... print 'not empty'
...
>>>
--
Joel Goldstick
http://joelgoldstick.com/ <http://joelgoldstick.com/stats/birthdays>
http://cc-baseballstats.info/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web