Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Alan Gauld via Tutor
On 30/07/18 19:11, Zachary Ware wrote: > On Mon, Jul 30, 2018 at 1:08 PM Alan Gauld via Tutor wrote: >> There are lots of options including those suggested elsewhere. >> Another involves using get() which makes your function >> look like: >> >> def viceversa(d): >> new_d = dict() >> for k

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Zachary Ware
On Mon, Jul 30, 2018 at 1:08 PM Alan Gauld via Tutor wrote: > There are lots of options including those suggested elsewhere. > Another involves using get() which makes your function > look like: > > def viceversa(d): > new_d = dict() > for k in d: > for e in d[k]: > new

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Alan Gauld via Tutor
On 30/07/18 13:40, Valerio Pachera wrote: > users = {'user1':['office-a', 'office-b'], > 'user2':['office-b'], > 'user3':['office-a','office-c']} > > It's a list of users. > For each user there's a list of room it can access to. > > I wish to get the same info but "sorted" by room. Re

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Peter Otten
Zachary Ware wrote: > On Mon, Jul 30, 2018 at 12:20 PM Valerio Pachera wrote: >> I was looking to substiture the cicle for e in new_d like this: >> [ new_d[e].append(k) if e in new_d else new_d[e].append(k) for e in >> [ d[k] ] >> but it can't work because 'new_d[e] = []' is missing. > > Hav

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Zachary Ware
On Mon, Jul 30, 2018 at 12:20 PM Valerio Pachera wrote: > I was looking to substiture the cicle for e in new_d like this: > [ new_d[e].append(k) if e in new_d else new_d[e].append(k) for e in d[k] ] > but it can't work because 'new_d[e] = []' is missing. Have a look at `dict.setdefault` and pla

[Tutor] Dictionary viceversa

2018-07-30 Thread Valerio Pachera
Hi all, consider this dictionary users = {'user1':['office-a', 'office-b'], 'user2':['office-b'], 'user3':['office-a','office-c']} It's a list of users. For each user there's a list of room it can access to. Generalizing, a dictionary with a list for each element. d = {k:list} I wi

Re: [Tutor] Dictionary Question

2016-05-03 Thread Michael Selik
On Mon, May 2, 2016 at 5:28 PM Jason N. via Tutor wrote: > Hello, > Wanted to ask if its possible to have a dictionary that can be looked up > by either values? > For example, > mydic = {"A: "Apple", "B": "Banana"}When user inputs "A" I want "Apple" to > come. But if the user enter "Apple" I want

Re: [Tutor] Dictionary Question

2016-05-03 Thread Michael Selik
On Mon, May 2, 2016 at 8:58 PM Jason N. via Tutor wrote: > What is the best way to make dictionary requests case in-sensitive? For > example, "Apple and "apple" should bring back the same dictionary > response. Thank you. > Take a look at how the requests library solves the problem with a "CaseI

Re: [Tutor] Dictionary Question

2016-05-03 Thread bharath ks via Tutor
Hello, Using iteritems would be much easier approach Something like this mydic = {"A": "Apple", "B": "Banana"} for key, value in mydic.iteritems():    if value == "Apple":        print key  Thanks & BR, Bharath Shetty On Tuesday, 3 May 2016 2:57 AM, Jason N. via Tutor wrote: Tha

Re: [Tutor] Dictionary Question

2016-05-02 Thread cs
On 03May2016 00:56, Jason N. wrote: Thank you all for your responses.  A quick follow up, what is the best way to make dictionary requests case in-sensitive? For example, "Apple and "apple" should bring back the same dictionary response. Thank you. There are a few ways depending what your mo

Re: [Tutor] Dictionary Question

2016-05-02 Thread isaac tetteh
If only I understand what you mean. You can just make all the values in the dictionary lower, upper or capitalized. Then if you want take an input or whatever you want to do with it just use .lower() or .upper() or .capitalized() to convert it to what is in the dictionary. Maybe someone has a be

Re: [Tutor] Dictionary Question

2016-05-02 Thread Jason N. via Tutor
Thank you all for your responses.  A quick follow up, what is the best way to make dictionary requests case in-sensitive? For example, "Apple and "apple" should bring back the same dictionary response. Thank you. On Monday, May 2, 2016 6:57 PM, Bob Gailer wrote: On May 2, 2016 5:27

Re: [Tutor] Dictionary Question

2016-05-02 Thread Bob Gailer
On May 2, 2016 5:27 PM, "Jason N. via Tutor" wrote: > > Hello, > Wanted to ask if its possible to have a dictionary that can be looked up by either values? > For example, > mydic = {"A: "Apple", "B": "Banana"}When user inputs "A" I want "Apple" to come. But if the user enter "Apple" I want "A" to

Re: [Tutor] Dictionary Question

2016-05-02 Thread Alan Gauld via Tutor
On 02/05/16 22:55, isaac tetteh wrote: > > For some reason i cant find reply all . But try this > for key, value in mydic.items(): > If A==value: >Print key or as a function: def findKey(dct, val): for k,v in dct.items(): if v == val: return k mydic = {"A: "

Re: [Tutor] Dictionary Question

2016-05-02 Thread isaac tetteh
Sorry for the if statement the correct statement should be "if 'apple' ==value:" Sent from my iPhone > On May 2, 2016, at 4:58 PM, isaac tetteh wrote: > > > For some reason i cant find reply all . But try this > for key, value in mydic.items(): > If A==value: > Print key > Nb:

Re: [Tutor] Dictionary Question

2016-05-02 Thread isaac tetteh
For some reason i cant find reply all . But try this for key, value in mydic.items(): If A==value: Print key Nb: use iteritems() if using python2 Sent from my iPhone > On May 2, 2016, at 4:29 PM, Jason N. via Tutor wrote: > > Hello, > Wanted to ask if its possible to have a d

[Tutor] Dictionary Question

2016-05-02 Thread Jason N. via Tutor
Hello, Wanted to ask if its possible to have a dictionary that can be looked up by either values? For example,  mydic = {"A: "Apple", "B": "Banana"}When user inputs "A" I want "Apple" to come. But if the user enter "Apple" I want "A" to respond. Please let me know the best way to handle this type

Re: [Tutor] Dictionary on data

2015-11-20 Thread Peter Otten
jarod_v6--- via Tutor wrote: > Dear All! > I have this elements > > In [445]: pt = line.split("\t")[9] > > In [446]: pt > Out[446]: 'gene_id "ENSG0223972"; gene_version "5"; transcript_id > "ENST0456328"; transcript_version "2"; exon_number "1"; gene_name > "DDX11L1"; gene_source "havan

[Tutor] Dictionary on data

2015-11-20 Thread jarod_v6--- via Tutor
Dear All! I have this elements In [445]: pt = line.split("\t")[9] In [446]: pt Out[446]: 'gene_id "ENSG0223972"; gene_version "5"; transcript_id "ENST0456328"; transcript_version "2"; exon_number "1"; gene_name "DDX11L1"; gene_source "havana"; gene_biotype "transcribed_unprocessed_pse

Re: [Tutor] Dictionary Issue

2015-08-08 Thread Alan Gauld
On 08/08/15 00:05, Ltc Hotspot wrote: Hi Alan, On line 15, I replaced: 'count[address] = count.get(address, 0) + 1' with 'line = Counter(address)'. line = Counter(address) will create a new Counter object with the address in it with a count value of 1. Every line in the file will create a n

Re: [Tutor] Dictionary Issue

2015-08-07 Thread Alan Gauld
On 07/08/15 19:18, Ltc Hotspot wrote: I want to find the max val , keys and values are defined on line 10: for kee, val in count.items(): Yes we know that, but you are not answering the questions we pose. Instead you seem to post random changes to your code and ask new questions which makes

Re: [Tutor] Dictionary Issue

2015-08-07 Thread Ltc Hotspot
Hi Mark, Why is Counter not defined on line #15: line = Counter(address),i.e., NameError: name 'Counter' is not defined? Share a chat session at http://tinyurl.com/oull2fw View line entry at http://tinyurl.com/oggzn97 Hal On Fri, Aug 7, 2015 at 12:14 AM, Mark Lawrence wrote: > On 07/08/2015 0

Re: [Tutor] Dictionary Issue

2015-08-07 Thread Ltc Hotspot
Alan, I want to find the max val , keys and values are defined on line 10: for kee, val in count.items(): Then, maxval determines the max value on line 11: if val > maxval: right, view a copy of the revised code at http://tinyurl.com/nvzdw8k Question1: are these assumptions true, above? Ques

Re: [Tutor] Dictionary Issue

2015-08-07 Thread Emile van Sebille
On 8/6/2015 5:30 PM, Ltc Hotspot wrote: I'm following the instructor's video exercise, available at https://www.youtube.com/watch?v=3cwXN5_3K6Q. As you're clearly interested in learning python, you may find working the tutorial beneficial as it steps you through the fundamentals of python i

Re: [Tutor] Dictionary Issue

2015-08-07 Thread Mark Lawrence
On 07/08/2015 01:30, Ltc Hotspot wrote: Mark, I'm following the instructor's video exercise, available at https://www.youtube.com/watch?v=3cwXN5_3K6Q. View attached screen shot file, image file shows a copy of the counter: cou[wrd] =cou.get(wrd,0) +1 Please, explain the differences in counter

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Alan Gauld
On 07/08/15 01:15, Ltc Hotspot wrote: Question1: How type of argument should I use for dict, i.e.,user argument or list argument. Read captured traceback: TypeError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\assignment_9_4_26.py in () 1 fname = raw_input("Ente

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
Mark, I'm following the instructor's video exercise, available at https://www.youtube.com/watch?v=3cwXN5_3K6Q. View attached screen shot file, image file shows a copy of the counter: cou[wrd] =cou.get(wrd,0) +1 Please, explain the differences in counter methods? Hal On Thu, Aug 6, 2015 at 4

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
Question1: How type of argument should I use for dict, i.e.,user argument or list argument. Read captured traceback: TypeError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\assignment_9_4_26.py in () 1 fname = raw_input("Enter file name: ") 2 handle = open (fn

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Mark Lawrence
On 06/08/2015 20:05, Ltc Hotspot wrote: On my breath and soul, I did: Counter objects have a dictionary interface except that they return a zero count for missing items instead of raising a KeyError : That's nice to know. What do the

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Alan Gauld
On 07/08/15 00:11, Ltc Hotspot wrote: Questions(1):Why does print line, prints blank space; and, (2) print address prints a single email address: See my previous emails. You are not storing your addresses so address only holds the last address in the file. line is at the end of the file so is

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
On Thu, Aug 6, 2015 at 3:00 PM, Alan Gauld wrote: > On 06/08/15 19:30, Ltc Hotspot wrote: > > I moved counter outside the loop and below dict, maxval = None >> maxkee = None are both positioned outside the loop. >> > > You moved counter but it is still a dict() and you > don't use it anywhere. >

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Alan Gauld
On 06/08/15 19:30, Ltc Hotspot wrote: I moved counter outside the loop and below dict, maxval = None maxkee = None are both positioned outside the loop. You moved counter but it is still a dict() and you don't use it anywhere. URL link to the revisions are available at http://tinyurl.com/nvz

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
On my breath and soul, I did: Counter objects have a dictionary interface except that they return a zero count for missing items instead of raising a KeyError : >>> >>> c = Counter(['eggs', 'ham']) On Thu, Aug 6, 2015 at 11:59 AM, Mark

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
Mark, Visit the following URL link to view a captured copy of the latest code revision, available at http://tinyurl.com/nvzdw8k Regards, Hal On Thu, Aug 6, 2015 at 10:17 AM, Ltc Hotspot wrote: > > > On Thu, Aug 6, 2015 at 8:28 AM, Mark Lawrence > wrote: > >> On 06/08/2015 05:22, Ltc Hotspot w

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
Hi Alan, I moved counter outside the loop and below dict, maxval = None maxkee = None are both positioned outside the loop. URL link to the revisions are available at http://tinyurl.com/nvzdw8k Question: How do I define Counter Revised code reads: fname = raw_input("Enter file name: ") handle =

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Alan Gauld
On 06/08/15 18:17, Ltc Hotspot wrote: Replace count[address]= count.get(address,0) +1 with c = Counter(['address'])? You didn't do what Mark suggested. Did you read the documentation about Counter? NameError Traceback (most recent call last) 2 handle = open (fname, 'r') > 3 c =

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Mark Lawrence
On 06/08/2015 18:17, Ltc Hotspot wrote: On Thu, Aug 6, 2015 at 8:28 AM, Mark Lawrence wrote: On 06/08/2015 05:22, Ltc Hotspot wrote: Please don't top post here, it makes following long threads difficult. Mark, Replace count[address]= count.get(address,0) +1 with c = Counter(['address'])?

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Alan Gauld
On 06/08/15 18:17, Ltc Hotspot wrote: View revised code here: fname = raw_input("Enter file name: ") handle = open (fname, 'r') c = Counter(['address']) count = dict () maxval = None maxkee = None for kee, val in count.items(): maxval = val maxkee = kee for line in handle:

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
On Thu, Aug 6, 2015 at 8:28 AM, Mark Lawrence wrote: > On 06/08/2015 05:22, Ltc Hotspot wrote: > > Please don't top post here, it makes following long threads difficult. > > Mark, >> >> Replace count[address]= count.get(address,0) +1 with c = >> Counter(['address'])? >> > > Try it at the intera

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Mark Lawrence
On 06/08/2015 05:22, Ltc Hotspot wrote: Please don't top post here, it makes following long threads difficult. Mark, Replace count[address]= count.get(address,0) +1 with c = Counter(['address'])? Try it at the interactive prompt and see what happens. Regards, Hal On Wed, Aug 5, 2015 at

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Alan Gauld
On 06/08/15 03:27, Ltc Hotspot wrote: The output as reported by the latest code revision: c...@iupui.edu 1← Mismatch Looks like python continues to print the wrong data set: Python will print what you ask it to. Don't blame the tool! :-) > for line in handle: >

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
Mark, Replace count[address]= count.get(address,0) +1 with c = Counter(['address'])? Regards, Hal On Wed, Aug 5, 2015 at 9:03 PM, Mark Lawrence wrote: > On 05/08/2015 23:58, Ltc Hotspot wrote: > >> Hi Mark, >> >> Address identifies the email address with the maximum number of sends: >> c...

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
Hi Alan The output as reported by the latest code revision: c...@iupui.edu 1 ← Mismatch Looks like python continues to print the wrong data set: In [11]: print val 1 In [12]: print kee r...@media.berkeley.edu In [13]: print address c...@iupui.edu In order to complete the assignment, using data

Re: [Tutor] Dictionary Issue

2015-08-06 Thread Ltc Hotspot
The revised output reads: In [3]: %run assignment_9_4_9.py Enter file name: mbox-short.txt c...@iupui.edu 14 The desired output: c...@iupui.edu 5 Question: How do I trace the source of the count? Revised data code reads: fname = raw_input("Enter file name: ") handle = open (fname, 'r') count

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Mark Lawrence
On 05/08/2015 23:58, Ltc Hotspot wrote: Hi Mark, Address identifies the email address with the maximum number of sends: c...@iupui.edu. Secondly, we are missing a count on the number of messages sent by c...@iupui.edu, i.e., 5. Thirdly, maxval 'none' is not defined on line # 24 Questions: Ho

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Alan Gauld
On 06/08/15 02:05, Ltc Hotspot wrote: The revised output reads: In [3]: %run assignment_9_4_9.py Enter file name: mbox-short.txt c...@iupui.edu 14 The desired output: c...@iupui.edu 5 See my other post. Count the number of letters in the addres

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Alan Gauld
On 05/08/15 23:58, Ltc Hotspot wrote: fname = raw_input("Enter file name: ") handle = open (fname, 'r') for line in handle: if line.startswith("From: "): address = line.split()[1] So far so good. ## The program creates a Python dictionary that maps ## the sender's mail addres

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Ltc Hotspot
Hi Mark, Address identifies the email address with the maximum number of sends: c...@iupui.edu. Secondly, we are missing a count on the number of messages sent by c...@iupui.edu, i.e., 5. Thirdly, maxval 'none' is not defined on line # 24 Questions: How do we define the value of none for the k

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Alan Gauld
On 05/08/15 15:15, Ltc Hotspot wrote: Raw data code reads: Being picky here but data and code are very different things (in most languages at least) and what you have below is definitely code not data. Meanwhile there are lots of issues in this code... fname = raw_input("Enter file name: ")

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Alan Gauld
On 05/08/15 23:36, Clayton Kirkwood wrote: It looks like the problem is with count=dict() Should be count=dict{} I may be wrong - U'm still a neophyte. Yes, you're wrong! :-) the correct form is as shown count = dict() Its calling the type operation which looks like any other function and

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Clayton Kirkwood
> -Original Message- > From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On > Behalf Of Mark Lawrence > Sent: Wednesday, August 05, 2015 3:23 PM > To: tutor@python.org > Subject: Re: [Tutor] Dictionary Issue > > On 05/08/2015 15:15, Ltc Hotspo

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Danny Yoo
> However, there is a traceback message: > > In [40]: %run 9_4_4.py > File "C:\Users\vm\Desktop\apps\docs\Python\_9_4_4.py", line 19 > count = dict() > ^ > SyntaxError: invalid syntax Syntax error reporting is approximate: you might need to look a few lines earlier to get at the root

Re: [Tutor] Dictionary Issue

2015-08-05 Thread Mark Lawrence
On 05/08/2015 15:15, Ltc Hotspot wrote: Hi everyone: I want to write a python program that reads through the data file of mbox-short.txt.Mbox-short.txt, i.e., download is available at http://www.py4inf.com/code/mbox-short.txt. Secondly, I want for python to figure out who sent the greatest num

[Tutor] Dictionary Issue

2015-08-05 Thread Ltc Hotspot
Hi everyone: I want to write a python program that reads through the data file of mbox-short.txt.Mbox-short.txt, i.e., download is available at http://www.py4inf.com/code/mbox-short.txt. Secondly, I want for python to figure out who sent the greatest number of mail messages. The output should r

Re: [Tutor] dictionary of lists

2015-06-04 Thread Chris Stinemetz
On Thu, Jun 4, 2015 at 2:30 AM, Peter Otten <__pete...@web.de> wrote: > Chris Stinemetz wrote: > >> Although I am certain it is not very efficient I was able to >> accomplish what I wanted with the following code I wrote: >> >> import os >> import pprint >> import csv >> from collections import def

Re: [Tutor] dictionary of lists

2015-06-04 Thread Peter Otten
Chris Stinemetz wrote: > Although I am certain it is not very efficient I was able to > accomplish what I wanted with the following code I wrote: > > import os > import pprint > import csv > from collections import defaultdict > > print_map = {'MOU':0, 'Call_Att':1, 'Device':2} > header = ['IME

Re: [Tutor] dictionary of lists

2015-06-03 Thread Chris Stinemetz
> >> Resetting execution engine >> Running >> C:\Users\cs062x\Desktop\python\projects\PanHandle\PanHandle\PanHandle.py >> The Python REPL process has exited > > > That's slightly unusual. How are you running this? > I am running it with Microsoft Visual Studio Community 2013 using Python Tools for

Re: [Tutor] dictionary of lists

2015-06-03 Thread Alan Gauld
On 03/06/15 17:39, Chris Stinemetz wrote: I am trying to create a dictionary of lists as I read a file. I envision it looking like: {key: [float_type],[string_type]} Thats not a dictionary of lists. You maybe mean: {key: [[float_type],[string_type]]} Which is a dictionary of lists of lists?

[Tutor] dictionary of lists

2015-06-03 Thread Chris Stinemetz
I am trying to create a dictionary of lists as I read a file. I envision it looking like: {key: [float_type],[string_type]} For the first item in the list I am trying to add the value to the existing value where the key matches but I am getting the following error: Resetting execution engine Runn

Re: [Tutor] dictionary keys

2014-04-09 Thread Alex Kleider
On 2014-04-08 23:55, Peter Otten wrote: You can create and sort the list in a single step: l = sorted(myDict) Thank you again; this is a new idiom for me. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https:

Re: [Tutor] dictionary keys

2014-04-08 Thread Peter Otten
Alex Kleider wrote: > On 2014-04-08 14:34, Peter Otten wrote: > >> That's a change in Python 3 where dict.keys() no longer creates a list, >> but >> instead creates a view on the underlying dict data thus saving time and >> space. In the rare case where you actually need a list you can >> explici

Re: [Tutor] dictionary keys

2014-04-08 Thread Alex Kleider
On 2014-04-08 14:34, Peter Otten wrote: That's a change in Python 3 where dict.keys() no longer creates a list, but instead creates a view on the underlying dict data thus saving time and space. In the rare case where you actually need a list you can explicitly create one with ips = list(ipD

Re: [Tutor] dictionary keys

2014-04-08 Thread Peter Otten
Alex Kleider wrote: > I've got a fairly large script that uses a dictionary (called 'ipDic') > each > value of which is a dictionary which in turn also has values which are > not > simple types. > Instead of producing a simple list, > """ > ips = ipDic.keys() > print(ips) > """ > yields > """ > di

[Tutor] dictionary keys

2014-04-08 Thread Alex Kleider
I've got a fairly large script that uses a dictionary (called 'ipDic') each value of which is a dictionary which in turn also has values which are not simple types. Instead of producing a simple list, """ ips = ipDic.keys() print(ips) """ yields """ dict_keys(['61.147.107.120', '76.191.204.54',

Re: [Tutor] Dictionary from a text file

2013-10-31 Thread Danny Yoo
> > > Note: in* 'call' : Update* ,Update it is a function defined in my python > script. My dictionary is too large so i taught rather than using directly > in python program I save it in a text file and when needed i assign it to > dictionary object . How can i assign this text file to dictionary

Re: [Tutor] Dictionary from a text file

2013-10-31 Thread bob gailer
On 10/31/2013 2:16 AM, Nitish Kunder wrote: I have a dictionary which is in this format for ex: { '5x' : { '50' : { 'update' : { 'update-from-esxi5.0-5.0_update01' : { 'call' : Update, 'name' : 'Update50u1', 'release' : '15/03/12' }, 'update-from-esxi5.0-5.0_update02' : { 'call' : Update, 'name'

Re: [Tutor] Dictionary from a text file

2013-10-31 Thread Peter Otten
Nitish Kunder wrote: > I have a dictionary which is in this format > for ex: > > { > '5x' : { > '50' : { > 'update' : { > 'update-from-esxi5.0-5.0_update01' : { > 'call' : Update, > 'name' : 'Update50u1', > 'release' : '15/03/12' > }, > 'update-from-esxi5.0-5.0_update02' : { > 'call' : Update, >

[Tutor] Dictionary from a text file

2013-10-31 Thread Nitish Kunder
I have a dictionary which is in this format for ex: { '5x' : { '50' : { 'update' : { 'update-from-esxi5.0-5.0_update01' : { 'call' : Update, 'name' : 'Update50u1', 'release' : '15/03/12' }, 'update-from-esxi5.0-5.0_update02' : { 'call' : Update, 'name' : 'Update50u2', 'release' : '21/12/12' }, },

Re: [Tutor] Dictionary get method

2013-03-20 Thread Mitya Sirenef
On 03/20/2013 04:21 AM, Peter Otten wrote: Phil wrote: On 20/03/13 15:09, Mitya Sirenef wrote: By the way, you can further simplify it by doing: def histogram2(s): return {c: d.get(c,0)+1 for c in s} That will work in python 3, in python 2 you need: return dict((c: d.get(c,0)

Re: [Tutor] Dictionary get method

2013-03-20 Thread Peter Otten
Phil wrote: > On 20/03/13 15:09, Mitya Sirenef wrote: > > >> >> By the way, you can further simplify it by doing: >> >> def histogram2(s): >> return {c: d.get(c,0)+1 for c in s} >> >> >> That will work in python 3, in python 2 you need: >> >> return dict((c: d.get(c,0)+1) for c in s) >

Re: [Tutor] Dictionary get method

2013-03-20 Thread Phil
On 20/03/13 15:09, Mitya Sirenef wrote: By the way, you can further simplify it by doing: def histogram2(s): return {c: d.get(c,0)+1 for c in s} That will work in python 3, in python 2 you need: return dict((c: d.get(c,0)+1) for c in s) Thanks again Mitya, although I'm not sur

Re: [Tutor] Dictionary get method

2013-03-20 Thread Phil
On 20/03/13 14:54, Amit Saha wrote: Hello Phil, On Wed, Mar 20, 2013 at 12:54 PM, Phil wrote: Thank you for reading this. I'm working my way through a series of exercises where the author only provides a few solutions. The reader is asked to modify the histogram example so that it uses the g

Re: [Tutor] Dictionary get method

2013-03-19 Thread Mitya Sirenef
On 03/20/2013 01:09 AM, Mitya Sirenef wrote: By the way, you can further simplify it by doing: def histogram2(s): return {c: d.get(c,0)+1 for c in s} That will work in python 3, in python 2 you need: return dict((c: d.get(c,0)+1) for c in s) Sorry, it should use a comma: return

Re: [Tutor] Dictionary get method

2013-03-19 Thread Mitya Sirenef
On 03/19/2013 10:54 PM, Phil wrote: Thank you for reading this. > > I'm working my way through a series of exercises where the author only provides a few solutions. > > The reader is asked to modify the histogram example so that it uses the get method thereby eliminating the if and else state

Re: [Tutor] Dictionary get method

2013-03-19 Thread Amit Saha
Hello Phil, On Wed, Mar 20, 2013 at 12:54 PM, Phil wrote: > Thank you for reading this. > > I'm working my way through a series of exercises where the author only > provides a few solutions. > > The reader is asked to modify the histogram example so that it uses the get > method thereby eliminati

Re: [Tutor] Dictionary get method

2013-03-19 Thread Mitya Sirenef
On 03/19/2013 10:54 PM, Phil wrote: Thank you for reading this. > > I'm working my way through a series of exercises where the author only provides a few solutions. > > The reader is asked to modify the histogram example so that it uses the get method thereby eliminating the if and else state

[Tutor] Dictionary get method

2013-03-19 Thread Phil
Thank you for reading this. I'm working my way through a series of exercises where the author only provides a few solutions. The reader is asked to modify the histogram example so that it uses the get method thereby eliminating the if and else statements. Histogram2 is my effort. The resul

Re: [Tutor] Dictionary

2012-06-18 Thread bob gailer
On 6/17/2012 2:26 PM, Selby Rowley-Cannon wrote: [snip] Do you have any programming (algorithm development) experience? Do you want to translate words independent of context? -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@pytho

Re: [Tutor] Dictionary

2012-06-17 Thread James Reynolds
Does this language have grammar independent of english? If no, just use .split() on the string and loop through that. If yes, well, its much more complicated On Jun 17, 2012 2:27 PM, "Selby Rowley-Cannon" wrote: > Version: 2.7 > OS: Ubuntu 12.04 LTS > > I am writing a small translation app for

[Tutor] Dictionary

2012-06-17 Thread Selby Rowley-Cannon
Version: 2.7 OS: Ubuntu 12.04 LTS I am writing a small translation app for Rydish (A language that exists in the same way Klingon does, invented by my company for a[n] RPG). Here is my current method of translation: Edictionary = {'English keys':'Rydish values'} TextEng = raw_input('Please ent

Re: [Tutor] dictionary of methods calling syntax

2012-02-08 Thread Mark Lawrence
On 08/02/2012 17:41, Gregory, Matthew wrote: Alan Gauld wrote: Since a class is effectively a disguised dictionary I'm not sure why you want to do this? If you just want to access the method by name then why not just call getattr(spam,'get_mean')? Thanks for the feedback and, yes, this makes s

Re: [Tutor] dictionary of methods calling syntax

2012-02-08 Thread Gregory, Matthew
Alan Gauld wrote: > Since a class is effectively a disguised dictionary I'm not sure why you > want to do this? If you just want to access the method by name then why > not just call getattr(spam,'get_mean')? Thanks for the feedback and, yes, this makes sense. My use case was when the statistic

Re: [Tutor] dictionary of methods calling syntax

2012-02-07 Thread Alan Gauld
On 07/02/12 19:32, Gregory, Matthew wrote: class Statistics(object): STAT = { 'MEAN': get_mean, 'SUM': get_sum, } ... if __name__ == '__main__': spam = Statistics(4, 3) print spam.get_stat('mean') print spam.get_stat('sum') Since a class is effect

Re: [Tutor] dictionary of methods calling syntax

2012-02-07 Thread Joel Goldstick
On Tue, Feb 7, 2012 at 2:32 PM, Gregory, Matthew wrote: > Hi list, > > I'm trying to understand how to use a class-level dictionary to act as a > switch for class methods.  In the contrived example below, I have the > statistic name as the key and the class method as the value. > > class Statist

[Tutor] dictionary of methods calling syntax

2012-02-07 Thread Gregory, Matthew
Hi list, I'm trying to understand how to use a class-level dictionary to act as a switch for class methods. In the contrived example below, I have the statistic name as the key and the class method as the value. class Statistics(object): STAT = { 'MEAN': get_mean, 'SUM': ge

Re: [Tutor] Dictionary to variable copy

2011-12-08 Thread Alan Gauld
On 08/12/11 09:03, sunil tech wrote: /Can i copy the content if a dictionary in to another variable, with out any link between the dictionary & the variable? if so, please teach. Yes, but they will both refer to the same object. But the two references will be entirely independant: D = {1:2,3:

Re: [Tutor] Dictionary to variable copy

2011-12-08 Thread Timo
Op 08-12-11 10:03, sunil tech schreef: /Can i copy the content if a dictionary in to another variable, with out any link between the dictionary & the variable? / Have a look at the copy module [1], or use the builtin dict.copy() method. Cheers, Timo [1] http://docs.python.org/library/copy.htm

[Tutor] Dictionary to variable copy

2011-12-08 Thread sunil tech
*Can i copy the content if a dictionary in to another variable, with out any link between the dictionary & the variable? if so, please teach. * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/

Re: [Tutor] Dictionary File character reader

2011-05-10 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Clara Mintz wrote: Sorry I am completely new at python and don't understand why this function is returning an empty dictionary. I want it to take a list of files open them then return the number of characters as the value and the file name as the key. def fileLengths

Re: [Tutor] Dictionary File character reader

2011-05-10 Thread Alan Gauld
"Noah Hall" wrote What you want is something that takes the length of each line, and add it to the sum. A simple way would be to do sum(len(line) for line in file) And if you just want the total count for the file an even simpler way is to use file.read() count = len(file.read()) One

Re: [Tutor] Dictionary File character reader

2011-05-09 Thread Noah Hall
On Tue, May 10, 2011 at 5:27 AM, Clara Mintz wrote: > Sorry I am completely new at python and don't understand why this function > is returning an empty dictionary. I want it to take a list of files open > them then return the number of characters as the value and the file name as > the key. > def

[Tutor] Dictionary File character reader

2011-05-09 Thread Clara Mintz
Sorry I am completely new at python and don't understand why this function is returning an empty dictionary. I want it to take a list of files open them then return the number of characters as the value and the file name as the key. def fileLengths(files):d = {}files = []for file in

Re: [Tutor] dictionary

2011-05-05 Thread Steven D'Aprano
louis leichtnam wrote: HEllo everyone, I have a dictionnary, and I would like to print only the values that have more/equal than 3 spaces in them for example: My name is Xavier. d = {1: "Hello world", 2: "My name is Xavier", 3: "ham and eggs", 4: "Eat more cheese please!", 5: "spam spam

Re: [Tutor] dictionary

2011-05-05 Thread naheed arafat
Supposing your dictionary like this: dict={1:'My name is X',2:'My name is x y z',3: 'i am X'} You can use len(list) : >>> dict={1:'My name is X',2:'My name is x y z',3: 'i am X'} >>> for values in dict.values(): ... if len(values.split(' '))>3: ...print values My name is X My name is x

[Tutor] dictionary

2011-05-05 Thread louis leichtnam
HEllo everyone, I have a dictionnary, and I would like to print only the values that have more/equal than 3 spaces in them for example: My name is Xavier. Can you help me out, Thanks Louis ___ Tutor maillist - Tutor@python.org To unsubscribe or chan

Re: [Tutor] Dictionary Question

2010-12-22 Thread Garry Bettle
On Wed, 22 Dec 2010 23:31:39 +1100, Steven D'Aprano wrote: > In this case, you need to sum the number of races for all the fixtures: > > num_races = sum(len(racetimes) for racetimes in FixtureDict.values()) Many thanks Steven for your explanation and final golden nugget of code. On Wed, 22 Dec 20

Re: [Tutor] Dictionary Question

2010-12-22 Thread bob gailer
On 12/22/2010 7:31 AM, Steven D'Aprano wrote: Also note: len(dict.keys()) == len(dict.values()) == len(dict) -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.p

Re: [Tutor] Dictionary Question

2010-12-22 Thread Steven D'Aprano
Garry Bettle wrote: Howdy all, Hope this message finds everyone well. I have dictionary of keys and a string of values. i.e. 8 Fixtures: I assume each fixture is a key, e.g. Swin, HGrn, etc. Swin1828 1844 1901 1916 1932 1948 2004 2019 2036 2052 2107 2122 HGrn1148 1204 1218 1232 12

[Tutor] Dictionary Question

2010-12-22 Thread Garry Bettle
Howdy all, Hope this message finds everyone well. I have dictionary of keys and a string of values. i.e. 8 Fixtures: Swin1828 1844 1901 1916 1932 1948 2004 2019 2036 2052 2107 2122 HGrn1148 1204 1218 1232 1247 1304 1319 1333 1351 Newc1142 1157 1212 1227 1242 1258 1312 1327 1344 140

Re: [Tutor] dictionary and more

2010-10-11 Thread Steven D'Aprano
On Tue, 12 Oct 2010 03:19:22 am Jack Uretsky wrote: > Hi- > I apologize for the size of the attached file, but the question > would make little sense if I made substantial deletions. > The program gives the following error: > Traceback (most recent call last): >File "/Javastuff/pyth

  1   2   3   >