3 Replies - 1400 Views - Last Post: 23 November 2012 - 08:51 PM Rate Topic: -----

#1 medaa  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 106
  • Joined: 24-October 12

Putting two ideas together into one function?

Posted 23 November 2012 - 01:43 PM

def build_dictionary(infile):

 infile=infile.strip(" ")
    count_dict={}
    alist=[]
    alist=infile.split()
    for lastname in alist:
        if lastname not in count_dict:
            count_dict[last]=1
        else:
            count_dict[number]=count_dict[number]+1

*This part counts the occurrences in the file and places them in the dictionary

for line in infile:
        line=line.strip()
        if len(line) and line[0]!="-":
            lst=line.split(",")
            lastname=lst[0].strip()

*This part reads the file lines


Ive tried many ways to put them together but I keep getting an error, can I get some help!

Is This A Good Question/Topic? 0
  • +

Replies To: Putting two ideas together into one function?

#2 medaa  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 106
  • Joined: 24-October 12

Re: Putting two ideas together into one function?

Posted 23 November 2012 - 01:53 PM

this is the file i want it to read

---- city: Edmonton
---- province: Alberta
Smith,Raymond
Szczesny,Julia
Smith,Rachel
Barbosa,Denilson
Tremblay,Sophie
Wilson, Gregory
Walters,Mark
---- city: Vancouver
---- province: BC
Harvey, Karen
Li,Russ
Smith,Michael
Ng,Andre
Barbosa,Anita
Turner, Jeremy
Lam,Annette
Was This Post Helpful? 0
  • +
  • -

#3 medaa  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 106
  • Joined: 24-October 12

Re: Putting two ideas together into one function?

Posted 23 November 2012 - 05:11 PM

figured it out!!
Was This Post Helpful? 0
  • +
  • -

#4 nunc  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 131
  • Joined: 20-November 11

Re: Putting two ideas together into one function?

Posted 23 November 2012 - 08:51 PM

Mind sharing your solution for anybody else who might have a similar problem?
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1