del并设置提案 [英] del and sets proposal

查看:72
本文介绍了del并设置提案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以执行以下操作:


a = [1,2,3,4,5]

del a [0]





a = {1:''1'',2:''2'',3:''3'',4:' '4'',5:''5''}

del a [1]


为什么套装不一样(特别是因为套装是基于一个

字典)?


a = set([1,2,3,4,5])

del a [1]


是的我知道集合有一个删除方法(如列表),但是因为字典

没有一个删除方法,不应该设置更像字典

而不像列表? IMHO del for sets非常直观。我想现在改变太晚了。


-Larry

解决方案

2008年10月2日星期四下午3:20,Larry Bates< la ********* @ vitalesafe.comwrote:


您可以执行以下操作:


a = [1,2,3,4,5]

del a [0]





a = {1:''1'',2:''''',3:''3'',4:'4 '',5:''5''}

del a [1]


为什么它对套装不起作用(特别是从套装基于

a字典)?


a =套装([1,2,3,4,5])

del a [1]



设置不支持下标,所以如果你不能去

''a_set [某事]'',为什么你能够能够这样的表达能够获得
''del''?订阅甚至意味着没有del的
?它没有意义,只会是

不一致。


>

是的我知道这些集合有一个删除方法(比如列表),但由于

字典没有删除方法,所以不应该设置更像

像词典和不像列表?集合的IMHO del是相当的



不,集合本身就是一种数据类型。它们基于内部的b
字典(至少在CPython中),但这是一个隐藏的

实现细节,没有强调。


直观。我想现在改变为时已晚。



最有可能。


干杯,

克里斯

-

沿着鬣蜥的路径......
http:/ /rebertia.com


>

-Larry

-
http://mail.python.org/mailman/listinfo/python-清单


10月2日,11:20 * pm,Larry Bates< larry.ba ... @ vitalEsafe.comwrote:


您可以执行以下操作:


a = [1,2,3,4,5]

del a [0]




a = {1:''1'',2:''2'' ,3:''3'',4:''4'',5:''5''}

del a [1]


为什么它对集合的作用不一样(特别是因为集合基于

字典)?


a =设定([1,2,3,4,5])

del a [1]


是我知道集合有一个删除方法(如列表),但由于字典

没有删除方法,所以不应该像行为更像字典

而不像列表? * IMHO del for sets非常直观。 *我想现在太晚了。


-Larry

< blockquote class =post_quotes>


>> a = set(range(5))
a [0]



Traceback(最近一次调用最后一次):

文件"< pyshell#15>",第1行,< module>

a [0]

TypeError:''set''对象是不可索引的


无论是否需要索引都没有意义。


还值得注意的是从容器中删除对象

(.remove)与提议将对象转到GC(del。 ..)


不得不同意del []在套装上有任何意义。


累了,已经晚了,所以可能打字垃圾,但是当我开始阅读小组的时候感觉还好。


Jon。


2008年10月2日星期四16:4 8:42 -0700,Jon Clements写道:


同样值得注意的是从容器中移除物品

(。 remove)不同于建议对象转到GC(del ...)



``del``并不建议对象转到GC,至少不是更多

然后`remove()`方法呢。就像`remove()```del``只删除

对象的引用一样。总是。


Ciao,

Marc''BlackJack''Rintsch


You can do the following:

a = [1,2,3,4,5]
del a[0]

and

a = {1:''1'', 2: ''2'', 3: ''3'', 4:''4'', 5:''5''}
del a[1]

why doesn''t it work the same for sets (particularly since sets are based on a
dictionary)?

a = set([1,2,3,4,5])
del a[1]

Yes I know that sets have a remove method (like lists), but since dictionaries
don''t have a remove method, shouldn''t sets behave like more like dictionaries
and less like lists? IMHO del for sets is quite intuitive. I guess it is too
late to change now.

-Larry

解决方案

On Thu, Oct 2, 2008 at 3:20 PM, Larry Bates <la*********@vitalesafe.comwrote:

You can do the following:

a = [1,2,3,4,5]
del a[0]

and

a = {1:''1'', 2: ''2'', 3: ''3'', 4:''4'', 5:''5''}
del a[1]

why doesn''t it work the same for sets (particularly since sets are based on
a dictionary)?

a = set([1,2,3,4,5])
del a[1]

Sets don''t support subscripting, so if you can''t go
''a_set[something]'', why would you expect to be able to be able to
''del'' such an expression? What would the subscription even mean
without the ''del''? It doesn''t make sense and would just be
inconsistent.

>
Yes I know that sets have a remove method (like lists), but since
dictionaries don''t have a remove method, shouldn''t sets behave like more
like dictionaries and less like lists? IMHO del for sets is quite

No, sets are a datatype unto themselves. They are based on
dictionaries internally (at least in CPython), but that''s an
implemention detail to be hidden, not emphasized.

intuitive. I guess it is too late to change now.

Most likely.

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com

>
-Larry
--
http://mail.python.org/mailman/listinfo/python-list


On Oct 2, 11:20*pm, Larry Bates <larry.ba...@vitalEsafe.comwrote:

You can do the following:

a = [1,2,3,4,5]
del a[0]

and

a = {1:''1'', 2: ''2'', 3: ''3'', 4:''4'', 5:''5''}
del a[1]

why doesn''t it work the same for sets (particularly since sets are based on a
dictionary)?

a = set([1,2,3,4,5])
del a[1]

Yes I know that sets have a remove method (like lists), but since dictionaries
don''t have a remove method, shouldn''t sets behave like more like dictionaries
and less like lists? *IMHO del for sets is quite intuitive. *I guess it is too
late to change now.

-Larry

>>a = set( range(5) )
a[0]

Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
a[0]
TypeError: ''set'' object is unindexable

No point it needing to be indexable either.

It''s also worth noting that removing an object from a container
(.remove) is different than proposing the object goes to GC (del...)

Have to disagree that del[] on a set makes any sense.

Tired, and it''s late, so probably typing rubbish, but felt okay when I
started reading the group :)

Jon.


On Thu, 02 Oct 2008 16:48:42 -0700, Jon Clements wrote:

It''s also worth noting that removing an object from a container
(.remove) is different than proposing the object goes to GC (del...)

``del`` doesn''t propose that the object goes to GC, at least not more
then a `remove()` method does. Just like `remove()` ``del`` only removes
references to objects. Always.

Ciao,
Marc ''BlackJack'' Rintsch


这篇关于del并设置提案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆