[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-10 Thread Antoine Pitrou


Change by Antoine Pitrou :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
type:  -> behavior
versions: +Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-10 Thread miss-islington


miss-islington  added the comment:


New changeset 972aba86ede0bf254e16a760639a1ff8df298578 by Antoine Pitrou in 
branch '3.8':
[3.8] bpo-40895: Update weakref documentation to remove old warnings (GH-20687) 
(GH-20792)
https://github.com/python/cpython/commit/972aba86ede0bf254e16a760639a1ff8df298578


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-10 Thread miss-islington


miss-islington  added the comment:


New changeset 049039832da3d02592d680cebf71ab8a665a6564 by Antoine Pitrou in 
branch '3.7':
[3.7] bpo-40895: Update weakref documentation to remove old warnings (GH-20687) 
(GH-20793)
https://github.com/python/cpython/commit/049039832da3d02592d680cebf71ab8a665a6564


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-10 Thread miss-islington


miss-islington  added the comment:


New changeset 18e07ba931c68eb5ab5262d4e57fe58c302686de by Miss Islington (bot) 
in branch '3.9':
bpo-40895: Update weakref documentation to remove old warnings (GH-20687)
https://github.com/python/cpython/commit/18e07ba931c68eb5ab5262d4e57fe58c302686de


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-10 Thread Antoine Pitrou


Change by Antoine Pitrou :


--
pull_requests: +19989
pull_request: https://github.com/python/cpython/pull/20793

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-10 Thread Antoine Pitrou


Change by Antoine Pitrou :


--
nosy: +pitrou
nosy_count: 3.0 -> 4.0
pull_requests: +19988
pull_request: https://github.com/python/cpython/pull/20792

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-10 Thread miss-islington


Change by miss-islington :


--
pull_requests: +19987
pull_request: https://github.com/python/cpython/pull/20791

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-10 Thread miss-islington


miss-islington  added the comment:


New changeset 1642c0ef750f96664a98cadb09301d492098d2fb by Daniel Fortunov in 
branch 'master':
bpo-40895: Update weakref documentation to remove old warnings (GH-20687)
https://github.com/python/cpython/commit/1642c0ef750f96664a98cadb09301d492098d2fb


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-06 Thread Daniel Fortunov


Change by Daniel Fortunov :


--
keywords: +patch
pull_requests: +19901
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/20687

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40895] weakref documentation contains cautions about dictionary mutation problems that have been solved in the implementation

2020-06-06 Thread Daniel Fortunov


New submission from Daniel Fortunov :

The doccumentation at https://docs.python.org/3.10/library/weakref.html 
cautions that the WeakKeyDictionary and WeakValueDictionary are susceptible to 
the problem of dictionary mutation during iteration.

These notes present the user with a problem that has no easy solution.

I dug into the implementation and found that fortunately, Antoine Pitrou 
already addressed this challenge (10 years ago!) by introducing an 
_IterationGuard context manager to the implementation, which delays mutation 
while an iteration is in progress.

I asked for confirmation and Antoine agreed that these notes could be removed:
https://github.com/python/cpython/commit/c1baa601e2b558deb690edfdf334fceee3b03327#commitcomment-39514438

--
assignee: docs@python
components: Documentation
messages: 370860
nosy: dfortunov, docs@python
priority: normal
severity: normal
status: open
title: weakref documentation contains cautions about dictionary mutation 
problems that have been solved in the implementation
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue40895>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Help about dictionary append

2012-02-06 Thread bruno.desthuilli...@gmail.com
On Feb 5, 4:29 pm, Andrew Berg bahamutzero8...@gmail.com wrote:
 This has nothing to do with dictionaries. If you want to add, delete, or
 change items, use a list (or a set if there aren't supposed to be any
 duplicates).

AND you don't care about ordering...

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


Help about dictionary append

2012-02-05 Thread Anatoli Hristov
Hi there,

I`m again confused and its the dictionary. As dictionary does not support
append I create a variable list with dictionary key values and want to add
new values to it and then copy it again to the dictionary as I dont know
other methods.

mydict =
{'Name':('Name1','Name2','Name3'),'Tel':('02','03','04')}

Then I use the key Name from the dict

name = mydict['Name']
and
tel = mydict['Tel']

then I want to add at the end new values and doing:

name.append('Name4')

and I get and error that TUPLE object has no attribute Append !!!

But how to add new Values to a dictionary then ?

I know its kind of basics in python, but I was seeking in the python
website and even google and could not realise that.

Thank you for your suggestions

A.H
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help about dictionary append

2012-02-05 Thread Chris Angelico
On Mon, Feb 6, 2012 at 2:13 AM, Anatoli Hristov toli...@gmail.com wrote:
 Hi there,

 I`m again confused and its the dictionary. As dictionary does not support
 append I create a variable list with dictionary key values and want to add
 new values to it and then copy it again to the dictionary as I dont know
 other methods.

A dictionary maps a key to exactly one value. If you want multiples,
you do pretty much what you've done here...

 mydict =
 {'Name':('Name1','Name2','Name3'),'Tel':('02','03','04')}
...
 and I get and error that TUPLE object has no attribute Append !!!

 But how to add new Values to a dictionary then ?

... but instead of using parentheses and creating a Tuple, use square
brackets and create a List:

mydict = {'Name':['Name1','Name2','Name3'],'Tel':['02','03','04']}

Then you can append to it, and it will work just fine!

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help about dictionary append

2012-02-05 Thread James Broadhead
On 5 February 2012 15:13, Anatoli Hristov toli...@gmail.com wrote:
 Hi there,

 I`m again confused and its the dictionary. As dictionary does not support
 append I create a variable list with dictionary key values and want to add
 new values to it and then copy it again to the dictionary as I dont know
 other methods.

 mydict =
 {'Name':('Name1','Name2','Name3'),'Tel':('02','03','04')}


dicts are intended to be used differently from this;
more like:

name_tel = {}
name_tel['Name1'] = 02
name_tel['Name2'] = 03
print name_tel['Name1']

... where Name is the key used to retrieve the value (the telephone number).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help about dictionary append

2012-02-05 Thread Andrew Berg
On 2/5/2012 9:13 AM, Anatoli Hristov wrote:
 and I get and error that TUPLE object has no attribute Append !!!
You defined mydict['name'] as a tuple, and tuples are immutable. Using a
tuple means that you don't ever want the values to change.

 But how to add new Values to a dictionary then ?
This has nothing to do with dictionaries. If you want to add, delete, or
change items, use a list (or a set if there aren't supposed to be any
duplicates). Information on built-in types is here:

http://docs.python.org/library/stdtypes.html (2.7)
http://docs.python.org/py3k/library/stdtypes.html (3.2)

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help about dictionary append

2012-02-05 Thread Anatoli Hristov
Thanks Chris,

It works fine, I see it will take time till I understand all the syntax :(

A.H

On Sun, Feb 5, 2012 at 4:20 PM, Chris Angelico ros...@gmail.com wrote:

 On Mon, Feb 6, 2012 at 2:13 AM, Anatoli Hristov toli...@gmail.com wrote:
  Hi there,
 
  I`m again confused and its the dictionary. As dictionary does not support
  append I create a variable list with dictionary key values and want to
 add
  new values to it and then copy it again to the dictionary as I dont know
  other methods.

 A dictionary maps a key to exactly one value. If you want multiples,
 you do pretty much what you've done here...

  mydict =
  {'Name':('Name1','Name2','Name3'),'Tel':('02','03','04')}
 ...
  and I get and error that TUPLE object has no attribute Append !!!
 
  But how to add new Values to a dictionary then ?

 ... but instead of using parentheses and creating a Tuple, use square
 brackets and create a List:

 mydict =
 {'Name':['Name1','Name2','Name3'],'Tel':['02','03','04']}

 Then you can append to it, and it will work just fine!

 Chris Angelico
 --
 http://mail.python.org/mailman/listinfo/python-list

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


simple question about Dictionary type containing List objects

2009-07-13 Thread gganesh
Hi group,
I have a dict object like
emails={'mycontacts': [ 'x...@gmail.com, 'y...@gmail.com',
'z...@gmail.com'], 'myname':['gganesh']}
I need to get the lenght of the list mycontacts ,like
mycontacts_numbers=3
help me to solve
Thanks


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


Re: simple question about Dictionary type containing List objects

2009-07-13 Thread Xavier Ho
On Mon, Jul 13, 2009 at 6:34 PM, gganesh ganesh@gmail.com wrote:

 Hi group,
 I have a dict object like
 emails={'mycontacts': [ 'x...@gmail.com, 'y...@gmail.com',
 'z...@gmail.com'], 'myname':['gganesh']}
 I need to get the lenght of the list mycontacts ,like
 mycontacts_numbers=3 http://mail.python.org/mailman/listinfo/python-list


 len(emails['mycontacts'])
3

HTH,

Ching-Yun Xavier Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple question about Dictionary type containing List objects

2009-07-13 Thread Ulrich Eckhardt
gganesh wrote:
 I have a dict object like
 emails={'mycontacts': [ 'x...@gmail.com, 'y...@gmail.com',
 'z...@gmail.com'], 'myname':['gganesh']}
 I need to get the lenght of the list mycontacts ,like
 mycontacts_numbers=3

mycontacts = emails['mycontacts']
mycontacts_number = len(mycontacts)

A list doesn't change in behaviour when it is contained in a dictionary.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


About dictionary in combobox in pygtk

2009-05-21 Thread shruti surve
hi all,

My data has thousands of entries. I 'd like to feed the combobox with
dictionary.how to use dictionary in combobox?


Regards,
shruti surve
-- 
http://mail.python.org/mailman/listinfo/python-list


about dictionary

2005-11-20 Thread Shi Mu
I have have the following code:
 a=[3,5,8,0]
 b={}

How I can i assign each item in a as the key in the dictionary b
simultaneously?
that is,
b={3:[],5:[],8:[],0:[]}
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about dictionary

2005-11-20 Thread [EMAIL PROTECTED]
b = dict([(x,dict()) for x in a])
Shi Mu wrote:
 I have have the following code:
  a=[3,5,8,0]
  b={}
 
 How I can i assign each item in a as the key in the dictionary b
 simultaneously?
 that is,
 b={3:[],5:[],8:[],0:[]}
 Thanks!

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


Re: about dictionary

2005-11-20 Thread Shi Mu
On 20 Nov 2005 02:59:30 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 b = dict([(x,dict()) for x in a])
 Shi Mu wrote:
  I have have the following code:
   a=[3,5,8,0]
   b={}
  
  How I can i assign each item in a as the key in the dictionary b
  simultaneously?
  that is,
  b={3:[],5:[],8:[],0:[]}
  Thanks!
Thanks!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about dictionary

2005-11-20 Thread Ben Finney
Shi Mu [EMAIL PROTECTED] wrote:
 I have have the following code:
  a=[3,5,8,0]
  b={}
 
 How I can i assign each item in a as the key in the dictionary b
 simultaneously?
 that is,
 b={3:[],5:[],8:[],0:[]}

Explicit:

a = [3, 5, 8, 0]
b = {}
for key in a:
b[key] = []

Quicker:

a = [3, 5, 8, 0]
b = dict( [(k, []) for k in a] )

What behaviour do you expect when there are repeated values in the
list 'a'?

-- 
 \ Faith may be defined briefly as an illogical belief in the |
  `\   occurrence of the improbable.  -- Henry L. Mencken |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about dictionary

2005-11-20 Thread przemek drochomirecki

Uzytkownik Shi Mu [EMAIL PROTECTED] napisal w wiadomosci
news:[EMAIL PROTECTED]
I have have the following code:
 a=[3,5,8,0]
 b={}

How I can i assign each item in a as the key in the dictionary b
simultaneously?
that is,
b={3:[],5:[],8:[],0:[]}
Thanks!


Other solution:
b.fromkeys(a,[])

cheers,

Przemek


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


Re: about dictionary

2005-11-20 Thread Peter Otten
przemek drochomirecki wrote:

 Uzytkownik Shi Mu [EMAIL PROTECTED] napisal w wiadomosci
 news:[EMAIL PROTECTED]
 I have have the following code:
 a=[3,5,8,0]
 b={}

 How I can i assign each item in a as the key in the dictionary b
 simultaneously?
 that is,
 b={3:[],5:[],8:[],0:[]}
 Thanks!
 
 
 Other solution:
 b.fromkeys(a,[])

Be warned that all keys share the same value.

 a = [3, 5, 8, 0]
 b = dict.fromkeys(a, [])
 b[3].append(42)
 b
{8: [42], 0: [42], 3: [42], 5: [42]}

Probably not what you want...

Peter

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


Re: about dictionary

2005-11-20 Thread Shi Mu
On 11/20/05, Peter Otten [EMAIL PROTECTED] wrote:
 przemek drochomirecki wrote:

  Uzytkownik Shi Mu [EMAIL PROTECTED] napisal w wiadomosci
  news:[EMAIL PROTECTED]
  I have have the following code:
  a=[3,5,8,0]
  b={}
 
  How I can i assign each item in a as the key in the dictionary b
  simultaneously?
  that is,
  b={3:[],5:[],8:[],0:[]}
  Thanks!
 
 
  Other solution:
  b.fromkeys(a,[])

 Be warned that all keys share the same value.

  a = [3, 5, 8, 0]
  b = dict.fromkeys(a, [])
  b[3].append(42)
  b
 {8: [42], 0: [42], 3: [42], 5: [42]}

 Probably not what you want...

 Peter
how to do with it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about dictionary

2005-11-20 Thread Peter Otten
Shi Mu wrote:

 how to do with it?

Use Ben Finney's, not Przemek's approach if the values are mutables that you
plan to modify. If that's what you are asking.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about dictionary

2005-11-20 Thread przemek drochomirecki

Uzytkownik Peter Otten [EMAIL PROTECTED] napisal w wiadomosci
news:[EMAIL PROTECTED]
 Shi Mu wrote:

  how to do with it?

 Use Ben Finney's, not Przemek's approach if the values are mutables that
you
 plan to modify. If that's what you are asking.

 Peter

Maybe he just want to use dictionary as a set.
He can use SET container instead.

Przemek


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


Re: about dictionary

2005-11-20 Thread Shi Mu
On 11/20/05, przemek drochomirecki [EMAIL PROTECTED] wrote:

 Uzytkownik Peter Otten [EMAIL PROTECTED] napisal w wiadomosci
 news:[EMAIL PROTECTED]
  Shi Mu wrote:
 
   how to do with it?
 
  Use Ben Finney's, not Przemek's approach if the values are mutables that
 you
  plan to modify. If that's what you are asking.
 
  Peter

 Maybe he just want to use dictionary as a set.
 He can use SET container instead.

 Przemek
How to use SET?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about dictionary

2005-11-20 Thread przemek drochomirecki

Uzytkownik Shi Mu [EMAIL PROTECTED] napisal w wiadomosci
news:[EMAIL PROTECTED]
On 11/20/05, przemek drochomirecki [EMAIL PROTECTED] wrote:

 Uzytkownik Peter Otten [EMAIL PROTECTED] napisal w wiadomosci
 news:[EMAIL PROTECTED]
  Shi Mu wrote:
 
   how to do with it?
 
  Use Ben Finney's, not Przemek's approach if the values are mutables that
 you
  plan to modify. If that's what you are asking.
 
  Peter

 Maybe he just want to use dictionary as a set.
 He can use SET container instead.

 Przemek
How to use SET?


http://docs.python.org/lib/types-set.html

 a
[3, 5, 8, 8]
 b = set(a)
 b
set([8, 3, 5])


cheers,
przemek


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


about dictionary

2005-11-20 Thread Shi Mu
d is a dictionary.
 d
{0: [[0, 1], [0, 2]], 1: [[0, 1], [1, 2], [1, 3]], 2: [[0, 2], [1, 2],
[2, 3]], 3: [[1, 3], [2, 3]]}

for the value under each key, if the possible connection is in the
dictionary, for example, under key 0. 1 and 2 were found to have a
pair in some other places so get [0,1,2]
hence, how to design a dictionary,
let dicTry=
{0: [[0, 1,2], 2: [[0, 1, 2], [1, 2,3]], 2: [[0, 1,2], [1, 2,3], 3: [1,2,3]}
Thanks a lot!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about dictionary

2005-11-20 Thread Bengt Richter
On Sun, 20 Nov 2005 07:12:08 -0800, Shi Mu [EMAIL PROTECTED] wrote:

d is a dictionary.
 d
{0: [[0, 1], [0, 2]], 1: [[0, 1], [1, 2], [1, 3]], 2: [[0, 2], [1, 2],
[2, 3]], 3: [[1, 3], [2, 3]]}

for the value under each key, if the possible connection is in the
dictionary, for example, under key 0. 1 and 2 were found to have a
pair in some other places so get [0,1,2]
hence, how to design a dictionary,
let dicTry=3D
{0: [[0, 1,2], 2: [[0, 1, 2], [1, 2,3]], 2: [[0, 1,2], [1, 2,3], 3: [1,2,3]=
}
Thanks a lot!
Sounds like some graph application? Maybe you can find something useful
in a link from
http://wiki.python.org/moin/PythonGraphApi

(which I found by googling for vertex graph site:python.org (without the 
quotes) ;-)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


about dictionary

2005-11-20 Thread Technical Support of Intercable Co
  b=dict.fromkeys(a)

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