473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

removing dictionary key-pair

JD

Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks
Jun 9 '06 #1
6 23239
JD>I try to remove a dictionary key-pair (remove an entry),
d = {1:2, 3:4}
d {1: 2, 3: 4} del d[1]
d

{3: 4}

Bye,
bearophile

Jun 9 '06 #2
JD wrote:
Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks


mydict = {"key" : "value"}
del mydict(key)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jun 9 '06 #3

JD wrote:
Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks


Assuming you know the key:

d = {"foo":1,"bar":2}
print d
del(d["foo"])
print d

Jun 9 '06 #4
bruno at modulix wrote:
JD wrote:
Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks

mydict = {"key" : "value"}
del mydict(key)


grmf... Typo. This is:

del mydict['key']

of course...
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jun 9 '06 #5

JD wrote:
Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks


d = dict(a=1, b=2, c=3)

print d

del d['a']

print d

Jun 9 '06 #6
JD wrote:
Hello,

I try to remove a dictionary key-pair (remove an entry),
but I'm unsuccessful. Does anyone know how to achieve this?

Thanks

d = {1: "one", 2: "two", 3: "three"}
del d[2]
d {1: 'one', 3: 'three'}


regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jun 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Tim N. van der Leeuw | last post by:
Hi, I'd like to remove keys from a dictionary, which are not found in a specific set. So it's kind of an intersection-operation. I can create a new dictionary, or a loop over all keys and test...
4
by: tarunbajaj | last post by:
Hi all, I am inserting a key in HttpContext.Cache Some keys I am caching for multiple days. Out of these once a while I need to reset cache entry of specific key. I can do a lot to reset the...
1
by: john wright | last post by:
I have a dictionary oject I created and I want to bind a listbox to it. I am including the code for the dictionary object. Here is the error I am getting: "System.Exception: Complex...
4
by: Nico Grubert | last post by:
Hi there, I am looking for a way to sort a list containing dictionaries. This is my example list: I want to sort the list by dictionary's key 'from_datetime' so the sorted list should be:
8
by: Brian L. Troutwine | last post by:
I've got a problem that I can't seem to get my head around and hoped somebody might help me out a bit: I've got a dictionary, A, that is arbitarily large and may contains ints, None and more...
6
by: Tina I | last post by:
Hi everyone, I have a small, probably trivial even, problem. I have the following HTML: I need to make this into a dictionary like this: dictionary = {"METAR:" : "ENBR 270920Z 00000KT 9999...
5
by: robinsiebler | last post by:
I have a data structure that looks like this: # dates = {'2007': {'25': {'06/23/07': {'aerosmith': , # 'Metallica': }, # 'last_song': }}}...
4
by: kdt | last post by:
Wow, I really am full of horrid questions today. I have a dictionary with a list of patterns: >>> words = {'sho.':6, '.ilk':8,'.an.':78 } Where the "." character means any pattern - this can...
1
GTXY20
by: GTXY20 | last post by:
Have a little bit of a problem: I have the following dictionaries: d={'1': , '3': , '2': , '4': } update={'a': 10, 'c': 4, 'b': 5, 'd': 1} I use the following to output:
4
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, having a dictionary of <int, string(C# 2.0) is there a way to retrieve the key for a specific value (of type string)? Obviously I populate the Dictionary with not duplicated strings. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.