PyCon Experience

Hi there,

I first heard of PyCon on my very first meeting with NYC PyLadies back in September 2013. Kat, an accomplished and creative Pythonista mentioned that it was a truly great and enriching experience to attend PyCon. If I remember well, I think that a member of NYC Python Meetup Group was present as well and corroborated Kat’s anecdote.

I was curious. I wished really hard to have one day the possibility to attend PyCon.

Today, I am having the privilege to attend PyCon 2014 thanks to the support of NYC PyLadies, Caktus Group and NumFocus. Can you imagine? I am ecstatic right now!

My objectives for PyCon 2014 are:

  • Thank in person PyLadies, Caktus Group and NumFocus.
  • Network with Pythonistas from around the world.
  • Learn from the conferences and fellow Pythonistas.
  • Visit every single booth and chat with the representatives.
  • Have a clear idea on what are the next steps in becoming an excellent programmer/Pythonista.
  • Have fun!

My dreams for PyCon 2014 are:

  • Meet a mentor.
  • Create long lasting connections with inspiring Programmers/Pythonistas.
  • Be inspired.

I will be at the PyLadies booth on Friday (11:00a.m. – 12:00 p.m. ). Come and say hi!

NYC PyLadies stamp

NYC PyLadies stamp

 

Chapter 9: Case Study – Word Play

 

 

Think Python Chapter 9: Case Study / Word Play

Think Python Chapter 9: Case Study / Word Play

Hi there!

 

I talked to my mentor (yes, after all this time I just found one!) about my increased frustration in solving certain problems from the book. For instance, I spend two weeks trying to solve by my own the exercises from chapter 4. It drove me literary crazy! Plus, I had the impression I was stagnating and start thinking about … maybe I am not good enough for this! … I know, hard stuff!

 

My mentor’s advice was: “Try to solve the problems in a given time (15, 30, 60 minutes). Then, peek at the answers and spend some time comparing your logic with the answer from the book.”

So, with this piece of advice, let us start Chapter 9.

9.1 Reading word lists

 

Python can read plain text files.

 

The built-in function open takes the name of the file as a parameter and returns a file object you can use to read the file.

 

file object: A value that represents an open file.

 

 

Open text files with Python

Open text files with Python

Python has several opening modes:

  • ‘r’ indicates that the file is open for reading
  • ‘w’ indicates that the file is open for writing

 

The file object provides several methods for reading including readline , reads characters from the file until it gets to a newline and returns the result as a string.

 

Assume that the file “names.txt” includes this list:

alexandra

alibaba

alysson

bethany

catherine

eleanor

francesca

giovanna

 

The first word in the ‘names’ list is “alexandra”.

 

Read text files with Python

Read text files with Python

 

We can get rid of the whitespace with the string method strip.

 

>>> fin = open ( ‘names.txt’ )

>>> line = fin.readline ( )

>>> name = line.strip ( )

>>> print name

alibaba

 

A file object can also be part of a for loop:

 

fin = open ( ‘names.txt’ )

for line in fin:

name = line.strip ( )

print name

 

9.3 Reading word lists

 

In this section Professor Downey points out that the exercises from Section 9.2 could be solved with the search pattern in Section 8.6.

problem recognition: It basically means not to re-invent the wheel. “[You] recognize the problem you are working on as an instance of a previously-solved problem, and apply a previously-developed solution.

 

9.4 Looping with indices

When we work with indices, many ways lead to Rome.

 

Looping with indices

Looping with indices

9.5 Debugging

So far, the programs we have written can be verified by hand (computing or searching /finding ourselves). However, we should start testing programs in a more systematic way.

 

Let us test the program “has_no_e”:

  • Test no1) Test words with an “e” at the beginning
  • Test no2) Test words with an “e” at the end
  • Test no3) Test words with an “e” somewhere in the middle
  • Test no4) Test long words
  • Test no5) Test short words
  • Test no6) Test very short words
  • Test no7) Perform the special case test. This test can

 

Special case: A test tat is typical or non-obvious (and less likely to be handled correctly).

 

 

***

Acknowledgments :

These notes represent my understanding from the book Think Python: How to Think Like a Computer Scientist written by Allen B. Downey.

Part of the chapter is transcribed and all the quotes unless specified otherwise come directly from his book.

Thank you Professor Downey for making this knowledge available.

 

Also, I would like to thank the open source community for their valuable contribution in making resources on programming available.

Thank you