On 21/06/2011 12:51, Gurpreet Singh wrote:
Perhaps this is the simplest and best solution which appears in this case. Just
copy the desired items to a new dictionary and discard the original one.
import re
myDict={'a':'alpha','b':'beta','c':'charley','d':'disney'}
myNewDict={}
for k,v in myDict
Perhaps this is the simplest and best solution which appears in this case. Just
copy the desired items to a new dictionary and discard the original one.
import re
myDict={'a':'alpha','b':'beta','c':'charley','d':'disney'}
myNewDict={}
for k,v in myDict.iteritems():
if re.search("a",v)!=None:
Terry Reedy wrote:
> Other situations will need other solutions.
>
Like a job's completion list.
Some number of workers get a job, and by time the caller sould know who and
what has finished. Then a dictionary would hold number of remaining jobs.
Similar a downloading list.
--
goto /dev/null
On 6/20/2011 10:30 AM, Florencio Cano wrote:
To make an example: imaging Bingo.Shuffle the numbers, each number sorted
should be removed from the container, how would it implemented?
The structure seems a set -> unordered collection of unique elements.
You can select a random element from the
> To make an example: imaging Bingo.Shuffle the numbers, each number sorted
> should be removed from the container, how would it implemented?
The structure seems a set -> unordered collection of unique elements.
You can select a random element from the set with
random.sample(container, num_of_ele
Lie Ryan wrote:
Thank you all for the information, really apreciated.
> While there are legitimate reasons for iterating a dictionary, I'd
> consider the alternatives first.
Perhaps the correct answer is in what you said.
For certain reasons, searching in a dictionary is the fastest method,
se
On 06/20/11 00:32, TheSaint wrote:
> Hello
>
> Trying to pop some key from a dict while is iterating over it will cause an
> exception.
> How I can remove items when the search result is true.
>
> Example:
>
> while len(dict):
>for key in dict.keys():
> if dict[key] is not my_result:
On 6/19/2011 11:53 AM, Roy Smith wrote:
Yet another variation which makes sense if you want to delete most of
the keys would be to copy them to a new dictionary. I'm not sure how
Python handles memory management on dictionaries which shrink.
'Python' does not handle memory management; each im
On 6/19/2011 11:13 AM, Chris Angelico wrote:
On Mon, Jun 20, 2011 at 12:32 AM, TheSaint wrote:
Hello
Trying to pop some key from a dict while is iterating over it will cause an
exception.
How I can remove items when the search result is true.
Example:
while len(dict):
for key in dict.keys
In article ,
Chris Angelico wrote:
> On Mon, Jun 20, 2011 at 12:32 AM, TheSaint wrote:
> > Hello
> >
> > Trying to pop some key from a dict while is iterating over it will cause an
> > exception.
> > How I can remove items when the search result is true.
> >
> > Example:
> >
> > while len(dict)
On Mon, Jun 20, 2011 at 12:32 AM, TheSaint wrote:
> Hello
>
> Trying to pop some key from a dict while is iterating over it will cause an
> exception.
> How I can remove items when the search result is true.
>
> Example:
>
> while len(dict):
> for key in dict.keys():
> if dict[key] is not m
Hello
Trying to pop some key from a dict while is iterating over it will cause an
exception.
How I can remove items when the search result is true.
Example:
while len(dict):
for key in dict.keys():
if dict[key] is not my_result:
dict.pop(key)
else:
condition_to_brea
12 matches
Mail list logo