Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 1,000 results for
dict
- Page 1
dict doesnt read properly
Programming
Software Development
15 Years Ago
by leegeorg07
… have this code currently: [code]
dict
= open("
dict
.txt", "r").readlines() print
dict
LETTERS={'a':1, 'b':2, 'c….lower() for i in range(len(
dict
)):
dict
[i] =
dict
[i][0:len(
dict
[i])-2] if word in
dict
: for letter in word: lettersv…
Re: dict doesnt read properly
Programming
Software Development
15 Years Ago
by jlm699
[QUOTE=leegeorg07;1046420] [code] for i in range(len(
dict
)):
dict
[i] =
dict
[i][0:len(
dict
[i])-2][/code][/QUOTE] What is that? What are you doing? EDIT: Also remember that
dict
is a reserved word in Python I suggest that you change the name
Re: dict() in python
Programming
Software Development
13 Years Ago
by raptr_dflo
I think you're confused about the
dict
notation. It's [CODE] d = {key:value, key:value, ...} [/CODE] …] = value [/CODE] if you want to use integers in your
dict
, instead of the strings in your list, simply do for… have no idea why you'd want or need a
dict
indexed by successive integers, that's what a list gets…
Re: dict() in python
Programming
Software Development
13 Years Ago
by jice
A classical method using list comprehensions [CODE]
dict
([(list[i], list[i+1]) for i in range(0, len(list), 2)]) [/CODE] function
dict
takes a list of tuples for arguments and uses the first term of the tuple as key and the second as value If you need more explanations, don't hesitate to ask.
dict() in python
Programming
Software Development
13 Years Ago
by rssk
…', '525', '179', '526', '180', '527', '181', '528', '182', '529'] using
dict
() i hav to map like.... [B]{0:344}{1:345…
List as value() in dict?
Programming
Software Development
14 Years Ago
by mandoza671
… keys and mydescriptions as a list of values. [CODE]
dict
= {} for line in file: mydesc,myword = line….split(',') if myword in
dict
:
dict
[myword] = list.append(mydescription) //is this correct? else:
dict
[myword] = create a new…a list as a value to the
dict
so it can be:
dict
[myword] = [number of mynumbers …
Invert Dict, with with key values as lists
Programming
Software Development
13 Years Ago
by slash16
want to do: [ICODE]
dict
= {'1': ['a'],'2': ['a', 'b', 'c']}[/ICODE] …know the one liner, if the
dict
was one to one, [ICODE]inverse =
dict
((d[k], k) for k…tried to get all of the values from the
dict
and made it a list then deleted duplicates,… using set, then compared original
dict
keys to check if the certain value existed …
finding key having max value in dict
Programming
Software Development
14 Years Ago
by parijat24
[CODE]
dict
= {'ENSTRUT00000047813': '1680', 'ENSTRUT00000047812': '2067', 'ENSTRUT00000047811': '2067', 'ENSTRUT00000047810': '2088', '…with max value from the
dict
I am using the [CODE] protein = max(
dict
.iteritems(),key=operator.itemgetter(1…i know that it sort the values in the
dict
and then give the max, but eventually it report…
Re: List as value() in dict?
Programming
Software Development
14 Years Ago
by Gribouillis
First, don't use the names of fundamental data types (like
dict
and list) as variable names. You could write [code=python] mydict = {} for line in file: mydesc,myword = [w.strip() for w in line.split(',')] if myword in mydict: mydict[myword].append(mydesc) else: mydict[myword] = [mydesc,] [/code]
Re: Invert Dict, with with key values as lists
Programming
Software Development
13 Years Ago
by TrustyTony
[CODE]reverse_d =
dict
( # invoking __init__ method of
dict
class to create dictionary # simple value from the generator in …
Re: Invert Dict, with with key values as lists
Programming
Software Development
13 Years Ago
by slash16
[QUOTE=pyTony;1702618][CODE]reverse_d =
dict
( # invoking __init__ method of
dict
class to create dictionary # simple value from the generator in …
GIFs in a Dict
Programming
Software Development
18 Years Ago
by mattyd
… such as GIF files as a value in a Python
Dict
; that is, is it possible to use GIF files in… a
Dict
and access them directly, rendering them to the screen via… the results of a RNG. At this point, using a
dict
seems the most promising considering the use of the "…
Re: finding key having max value in dict
Programming
Software Development
14 Years Ago
by -ordi-
[CODE]protein = max(
dict
.values(), key=int) print protein[/CODE] and [CODE]proteins = max(
dict
.iteritems(), key = lambda x:int(x[1]))[0][/CODE]
Re: finding key having max value in dict
Programming
Software Development
14 Years Ago
by TrustyTony
… not good name for a
dict
as it shadows the builtin type mydict = {'ENSTRUT00000047813': '1680', 'ENSTRUT00000047812': '…
disappearing dict key !!!
Programming
Software Development
13 Years Ago
by kwajo
… deleted the 6th bunny seems to be removed from the
dict
for one loop and it looks like this: {'gender': 'Female…': 'Sebastian'} the issue is that while its not in the
dict
the age of the key wont increase so on the…'} what i need help with if finding out where that
dict
key is going and why. thanks for the help :) P…
Re: Invert Dict, with with key values as lists
Programming
Software Development
13 Years Ago
by TrustyTony
…;> values set(['a', 'c', 'b']) >>> reverse_d =
dict
((new_key, [key for key,value in d.items() if new_key…
Re: Invert Dict, with with key values as lists
Programming
Software Development
13 Years Ago
by Gribouillis
…', 'c'],'2': ['a', 'b', 'c'], '3': ['b']} >>>
dict
((x, list(t[1] for t in group)) for (x…
Re: Invert Dict, with with key values as lists
Programming
Software Development
13 Years Ago
by slash16
Wow, thank you so much. But can you explain how the following line works, as in what each thing does? [CODE] >>> reverse_d =
dict
((new_key, [key for key,value in d.items() if new_key in value]) for new_key in values)[/CODE] Sorry new to python, it seems much different then pascal or php, which I am used to.
putting 2 values into dict
Programming
Software Development
13 Years Ago
by welshly_2010
hey i want to put two values into one
dict
and am not sure how to achieve this. i …] here my current code and what i currently getting in
dict
[code] myfile = open('auth','r') desc_ip = {} desc_ip['date'] = {} count_ip = … print ip ,' has', desc_ip[ip] , ' attacks' [/code] here my current
dict
[quote]{'213.251.192.26': 13, '218.241.173.35…
Re: Classes and Dict`s
Programming
Software Development
12 Years Ago
by Gribouillis
…object): ... def __init__(self): ... self.mydict =
dict
() # <-- a
dict
is added to every instance ... >>> …;>> class B(object): ... shareddict =
dict
() # <-- this
dict
can be used by all instances ... def __init__(… # <-- instances usually have a predefined
dict
to store attributes {}
Randint number into a Dict
Programming
Software Development
11 Years Ago
by Gaven
… after doing this I would like to add it to
Dict
or List and check if the number already added and… the list even if it is already in a list/
dict
. So I don't know which i should choice the…
Dict
or List or adding the numbers and which one for …
Re: convert json string to json dict
Programming
Software Development
11 Years Ago
by Gribouillis
Perhaps convert to
dict
first def main(args): f = open(args[1], 'w') inp = raw_input("Enter a
Dict
") # inp = {"a":1,"b":2} inp = django.utils.simplejson.loads(inp) assert isinstance(inp,
dict
) django.utils.simplejson.dumps(inp, f)
Subclassing dict
Programming
Software Development
15 Years Ago
by marcux
Hi all! I want to make a subclass of
dict
and I have read about subclassing and the super method. … not get is how I override the following method: [CODE]
dict
[key] = value[/CODE] This creates a new key with the…
Re: Subclassing dict
Programming
Software Development
15 Years Ago
by Gribouillis
You must overwrite the __setitem__ method [code=python] class mydict(
dict
): def __setitem__(self, key, value): doStuff() return
dict
.__setitem__(self, key, value) [/code]
add new key-value pair to a dict
Programming
Software Development
15 Years Ago
by checker
…;Enter an age: ")) g.sqrtage = sqrt(g.age) list1 =
dict
() list1[g.name] = g.age print g.name, g.age… I want to add new key-value pair to a
dict
list1 = {'joe': 11, 'john', 19} for example How do I…
Help required with dumping Python Dict and MySQL
Programming
Software Development
15 Years Ago
by girlscodetoo
… have the solution. Now I am stuck at dumping the
dict
contents to MySQL. Any help is really appreciated. Data : [QUOTE….execute("select * from myTable") rows = cursor.fetchall() data =
dict
() for row in rows: key, primary = row[0], row[1…
get all max values in dict
Programming
Software Development
14 Years Ago
by bpatt22
What approach should I use to return all
dict
keys that have the maximum value. The code below outputs 1, but I would like for it to return 1, 2. [CODE]import operator d1 =
dict
() d1[0] = 1 d1[1] = 2 d1[2] = 2 maxValue = max(d1.iteritems(), key=operator.itemgetter(1))[0] [/CODE]
Re: get all max values in dict
Programming
Software Development
14 Years Ago
by vegaseat
… be cleaner alternative using dictionary comprehensions. [CODE]import operator d1 =
dict
() d1[0] = 1 d1[1] = 2 d1[2] = 2 maxValue…] I don't think that works ... [code]import operator d1 =
dict
() d1[0] = 1 d1[1] = 8 d1[2] = 8 maxValue…
Do not understand Dict objects
Programming
Software Development
14 Years Ago
by spac_e
….page): def GET(self): query = models.Curricula.query.all() map =
dict
() for x in query: x = x.to_dict() map[x['owner_id… returns {"email": "Course3}. I tried adding map2 =
dict
() and adding the contents of the map to map2 while…
Re: disappearing dict key !!!
Programming
Software Development
13 Years Ago
by kwajo
… added to a dictionary using its (unique) name as the
dict
key. if you think it would be more practical for…
1
2
3
17
Next
Last
Search
Search
Forums
Forum Index
Hardware/Software
Recommended Topics
Programming
Recommended Topics
Digital Media
Recommended Topics
Community Center
Recommended Topics
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2025 DaniWeb® LLC