woooee 814 Nearly a Posting Maven

You want to return the string found from each of the functions, instead of writing it to a file. Then, if conditions are met, write them all to the file. So readfiles() would be similar to the following using your existing structure.

def readfiles(filename):
   filelist = open(filename)
   write_owner = ""
   write_name = ""
   for line in filelist:
      files = line[:-1]
      print files
      owner = add_ownerid(filename)
      if len(owner):      ## owner was found in the line
         write_owner = owner
      name = add_ownername(files)
      if len(name):
         write_name = name
      user = add_userid(files)
      ##  assumes that user id is the cut off point
      if len(user) and len(write_owner):
         write_data(write_owner, write_name, user)
         write_owner = ""
         write_name = ""
woooee 814 Nearly a Posting Maven

i have 2 list contaning 4 element

= 8 elements total

I must create 2 new list which contain 2 element

= 4 elements total. What happens to the other 4 elements?

woooee 814 Nearly a Posting Maven

This will yield the correct results using your test data, but you will have to figure out how to get it to work with your input file.

country = ["Germany","France","Italy"]
medals = ["Gold","Silver","Bronze"]
event = ["Luge men's single"]

data = {}
for this_country in country:              
    data[this_country] = {}
    for this_event in event:
        data[this_country][this_event] = []
        for this_medal in medals:
            data[this_country][this_event].append(this_medal)
    ## delete one element so all countries are different
    del medals[0]
for this_country in country:
    print this_country, data[this_country]
"""  My results
Germany {"Luge men's single": ['Gold', 'Silver', 'Bronze']}
France {"Luge men's single": ['Silver', 'Bronze']}
Italy {"Luge men's single": ['Bronze']}
"""
woooee 814 Nearly a Posting Maven

I tried just having '.10' hardcoded, but still had the same problem.

Which says you are overlaying it with something else, or the epsilon is pushing it off the page. If you are saving as postscript and not encapsulated postscript it is pretty easy to read the code as it is just a markup language.

Edit: From what I can tell you have a problem at the epsilon figure. It would depend on the font and the UTF that you are using. Epsilon, of course, would not be included in a normal English font, so you may have to draw it yourself as it is a fairly simple figure.

woooee 814 Nearly a Posting Maven

First see where /usr/bin/python points to as that is what is being called by the shebang in the first line of the program. It may be pointing to another version of Python that does not have Tkinter installed. Next, if you have a /usr/lib/site-packages/lib-tk, run one of the programs like "ScrolledText.py". Your versions appear to be OK. Ubuntu would package the correct versions together, so it's a good bet that /usr/bin/python, or /usr/local/bin/python points somewhere else. Try this

#!/usr/bin/python2.6

import Tkinter

and see if it runs.

woooee 814 Nearly a Posting Maven

Try "import Tkinter", note the capital "T". You have to have a match between the tkinter version and the TCL/Tk version. TCL & Tk should be subdirectories in /usr/lib and would be version 8.5 to go with Python 2.6x. Tkinter will be in /usr/lib/python/lib-tk. Also, python has to be compiled with Tkinter support. How did you build python and where did the code come from. Your distro should have prebuilt binaries for TCK, Tk, and Python with Tkinter support.

woooee 814 Nearly a Posting Maven

Two possibles would be to change
%.2f
to %3.2f which can mean a total of 3 bytes, one before and two after the decimal. If your OS interprets this way, then you originally have zero bytes allocated to the float. Second, omit the epsilon an see if the numbers print OK, i.e. the epsilon is overlaying the number (note the equal sign is missing as well).

woooee 814 Nearly a Posting Maven

He possibly means subtracting Jan 1st from today.

import datetime

today = datetime.datetime.now()
date_diff = today - datetime.datetime(today.year, 1, 1)
days_of_year = date_diff.days + 1
print days_of_year
woooee 814 Nearly a Posting Maven

You can sort a list of lists on any element using the operator itemgetter

import operator

test_list = [ ["a", "b", "c", "d", "e"],
              ["e", "d", "c", "b", "a"],
              ["c", "d", "e", "a", "b"] ]

for j in range(0, 5):
    print j
    s_list = sorted(test_list, key=operator.itemgetter(j))
    print s_list
woooee 814 Nearly a Posting Maven

You might want to re-think/modify the following.

if match:
    assign(filename, counter, path, extension)
    counter += 1
woooee 814 Nearly a Posting Maven

You have to strip() each line to get rid of spaces and newlines, and then test for length greater than zero. That will skip any lines with spaces only.

woooee 814 Nearly a Posting Maven

That's in every tutorial so you're not going to get many responses. Take a look at "Variables" here http://www.greenteapress.com/thinkpython/thinkCSpy/html/chap02.html And learn to print things.

print range(1, 6)
for x in range(1, 6):
    print x
woooee 814 Nearly a Posting Maven

Do not use things you do not understand. You may fix this error, or you may just make the error more subtle. You have no way of knowing since you don't understand it. This code has everything that you shouldn't do. And is probably done by a lazy coder. Pass the variable back and forth or learn to use classes (or spend the rest of your life beating your head against this wall).

def a_function_with_a_name_that_has_some_meaning(psyc_stat=False):
    print psyc_stat
    psyc_stat = not psyc_stat
    print psyc_stat
    return psyc_stat

ps = a_function_with_a_name_that_has_some_meaning()
print "-" * 10
ps = a_function_with_a_name_that_has_some_meaning(ps)
"""
My Results

False
True
----------
True
False
"""
woooee 814 Nearly a Posting Maven

Convert the integer to a list or string and iterate over each element/character. You can use a while loop or a for loop.

woooee 814 Nearly a Posting Maven

When driving around, take a look at how many motels still advertise "color TV" (about half?). It was a big deal back when but today you would just advertise "TV".

woooee 814 Nearly a Posting Maven

Giving my niece and nephews the old "we had it tough back in my day" routine, I told them that it was so tough that if we wanted to change the TV channel we had to get up off the couch, walk across the room, and turn the knob. They gave me that look that said they weren't sure if they believed it not, and one of them said "TV's don't have knobs".

woooee 814 Nearly a Posting Maven

You also have the following block of code in the middle of the functions, but it is not a function. To start, you might want to design the file read and write. One function would read the file and return a list. Another function would write the updated list to the file. You can use an indicator string at the beginning of each record, so name might start with "NM", and address with "AD", etc. This would avoid the calcs to determine if it is the first second or third record. But if you want to keep it the way it is just read three records at a time.

# Opening and reading file into a three arrays in a loop.
entries = "C:\Documents and Settings\Brenda\Desktop\
CSCD 110 Assignments\entries.txt"
fileInput = open("entries.txt", "r")
myList = fileInput.read()
count = 0
 
for myString in fileInput:
    myString = myString.strip()
    myString = mystring. lower()
    myNum = count % 3
    if myNum == 0:
        lastName.append(myString)
    elif myNum == 1:
        firstName.append(myString)
    elif myNum == 2:
        phoneNumber.append(myString)
    count = count + 1
fileInput.close()

And finally, this piece of code reads the file twice. The
myList = fileInput.read()
statement reads the entire file into myList. The
for myString in fileInput:
statement reads one record at a time, except there are no records to read because the previous read statement positioned the file pointer at the end of the file, so just eliminate the first read statement as below.

fileInput = open("entries.txt", "r") …
woooee 814 Nearly a Posting Maven

Sorry, I was too subtle. Generally, a "not a valid entry" message is printed when someone enters some other option. Also, you would generally have a message displayed for 4 = exit, but it is your menu and you can design it as you choose.

woooee 814 Nearly a Posting Maven

"This code is too confusing" is too vague to really respond to, but here is effbot's tutorial. Effbot is a good source for examples. http://effbot.org/tkinterbook/menu.htm

woooee 814 Nearly a Posting Maven

myList is always empty. And what happens when someone chooses '5'?

## *************************************
myList = []
## *************************************
option = displayMenu()
while option != '4': # Set up menu choices.
    if option == '1':
        getLastName(myList)
    elif option == '2':
        getFirstName(myList)
    elif option == '3':
        getPhoneNumber(myList)

    option = displayMenu()

print "\nThank you for looking.\n\n"

You might also take a look at the Python Styleguide. Code is easier to read when we all use the same conventions. http://www.python.org/dev/peps/pep-0008/ Finally, click the [ code ] icon at the top and post your code in between the tags.

woooee 814 Nearly a Posting Maven

No one is going to help you without knowing which f---- GUI toolkit you are using, and code posted between code tags --> click on the [ code ] icon at the top of the box, and post your code between the two code tags.

woooee 814 Nearly a Posting Maven

That's because the directory was changed in the bash shell (os.system) and not in the python shell. Why not just use
os.system("ls /opt/WindRiver")
or, since we now use subprocess
subprocess.call("ls /opt/WindRiver", shell=True)

You can use python's
os.chdir("/opt/WindRiver")
but it is better to always use absolute path names to avoid the type of error that you posted originally.

woooee 814 Nearly a Posting Maven

File "C:\Python26\getcard.py", line 22, in giveCard

It appears the error is in getcard.py, which you did not post, and not in testmod.py which you did post. The code you posted worked fine for me. BTW the following will only work for self.Tcard == 11, not if it equals 12 or 13.

if(self.Tcard <= 11 & self.Tcard != 14): 
              =================
                if(self.Tcard == 11):
                    self.Tcard = "J"
                if(self.Tcard == 12):
                    self.Tcard == "Q"
                if(self.Tcard == 13):
                    self.Tcard == "K"
                self.Sum+=10 
#
##----- a dictionary would work better than multiple if statements
card_dict = [ 11:"J", 12: "Q", 13:"K"}
if self.Tcard in card_dict:
    self.Tcard = card_dict[self.Tcard]

Finally, take a look at the Python Style Guide when you have time. It is easier to debug other people's code when we all use the same conventions http://www.python.org/dev/peps/pep-0008/

woooee 814 Nearly a Posting Maven

How do you get from here
Input String : XYZZXXYYXYZZXYZ

to here (and what happened to the final "Z")
Unique Prefixes :

to here [and is (3,'') the final Z]
Encode List : [(0, 'X'), (0, 'Y'), (0, 'Z'), (3, 'X'), (1, 'Y'), (2, 'X'), (2, 'Z'), (4, 'Y'), (3, '')]

and especially to here (using 9 bits per byte at least some of the time)
Encoded Binary String :
001011000 = "X"
001011001 = "Y"
0
001011010 = "Z"
?????
1101011000001010110010100101100000100101101001000101100100011
Decoded String : XYZZXXYYXYZZXYZ

woooee 814 Nearly a Posting Maven

You can not mix canvas and grid. To use a label, button, etc. you must add a frame to the canvas. The following example will get you started on this, as well as using a for loop to create the square.

##-------  Do not import Tkinter twice; use one or the other
from Tkinter import *
##import Tkinter as tk
 
def startMenu():
    top_tk = Tk()
    top_tk.title("Checkers")
    top = Canvas(width="800", height="800")

    square_list = []
    color = "white"
    for j in range(0, 701, 100):
        square_list.append(top.create_rectangle(j,0,j+100,100, fill=color))
        if color == "white":
            color = "black"
        else:
            color = "white"

    fr = Frame(top, relief=GROOVE, borderwidth=2)
    label1 = Label(fr, text='Checkers', font=('Arial', 36), fg="blue")
    label1.pack(side="left")

    top.create_window(210, 800, window=fr, anchor=SE)
    top.pack(fill='both', expand='yes')
 
    top.mainloop()
 
startMenu()
smithy40000 commented: Thanks alot! helped greatly +0
woooee 814 Nearly a Posting Maven

I need to check if a float number has decimals or not.

Convert to a string, split on the ".", and see if the number after the decimal is greater than zero. You can also use divmod which returns the whole and decimal parts of a number
x = 2.5
print divmod(x, 1)
(2.0, 0.5)

woooee 814 Nearly a Posting Maven

You can use the step function of a for loop to reverse every pair of two letters. The logic for removing a double letter would be similar.

def switch_letters(word):
   word_list = list(word)
   for j in range(1, len(word), 2):
      word_list[j-1], word_list[j] = word_list[j], word_list[j-1]
   return "".join(word_list)


print switch_letters("cat")
print switch_letters("antidisestablishmentarianism")
woooee 814 Nearly a Posting Maven

There is a discrepancy in these 2 statements. Is preorder a list, so preorder[0] can be None, or is preorder a string, i.e the second statement below?

if (preorder[0] or inorder[0]) is None: 
    if preorder is not None:
woooee 814 Nearly a Posting Maven

if (seq_record.seq[count] == "A") :

There is apparently a 32K limit on the number of records (short integer, signed). You will have to come up with a way to split the data up or use another method to read.

woooee 814 Nearly a Posting Maven

You don't have a newline on the last line of the test data so "\n" is never found". You can add a newline to the data or test for EOF and if -1 is not a newline, then add one.

def test_func(thetext):
        for i in range(1,26):
            t = 0
            for x in range(0,len(thetext)):
                if thetext[x] == '\n' and thetext[x-1] == str(i) and thetext[x-2] == '\n':
                    print 'one'
                    t = 1
                    break
                if (thetext[x-1:x-2]) == str(i):
                    print 'two'
                    t = 1
                    break
            if t == 0:
                print "{TAB}{TAB} " + str(i)

test_list = [ "1\n",
              "5\n",
              "16\n" ]

for ltr in test_list:
   test_func(ltr) 
#
"""     My Results
one
{TAB}{TAB} 2
{TAB}{TAB} 3
{TAB}{TAB} 4
{TAB}{TAB} 5
{TAB}{TAB} 6
{TAB}{TAB} 7
{TAB}{TAB} 8
{TAB}{TAB} 9
{TAB}{TAB} 10
{TAB}{TAB} 11
{TAB}{TAB} 12
{TAB}{TAB} 13
{TAB}{TAB} 14
{TAB}{TAB} 15
{TAB}{TAB} 16
{TAB}{TAB} 17
{TAB}{TAB} 18
{TAB}{TAB} 19
{TAB}{TAB} 20
{TAB}{TAB} 21
{TAB}{TAB} 22
{TAB}{TAB} 23
{TAB}{TAB} 24
{TAB}{TAB} 25
{TAB}{TAB} 1
{TAB}{TAB} 2
{TAB}{TAB} 3
{TAB}{TAB} 4
one
{TAB}{TAB} 6
{TAB}{TAB} 7
{TAB}{TAB} 8
{TAB}{TAB} 9
{TAB}{TAB} 10
{TAB}{TAB} 11
{TAB}{TAB} 12
{TAB}{TAB} 13
{TAB}{TAB} 14
{TAB}{TAB} 15
{TAB}{TAB} 16
{TAB}{TAB} 17
{TAB}{TAB} 18
{TAB}{TAB} 19
{TAB}{TAB} 20
{TAB}{TAB} 21
{TAB}{TAB} 22
{TAB}{TAB} 23
{TAB}{TAB} 24
{TAB}{TAB} 25
{TAB}{TAB} 1
{TAB}{TAB} 2
{TAB}{TAB} 3
{TAB}{TAB} 4
{TAB}{TAB} 5
{TAB}{TAB} 6
{TAB}{TAB} 7
{TAB}{TAB} 8
{TAB}{TAB} 9
{TAB}{TAB} 10
{TAB}{TAB} 11
{TAB}{TAB} 12
{TAB}{TAB} 13
{TAB}{TAB} 14
{TAB}{TAB} 15
two
{TAB}{TAB} 17
{TAB}{TAB} 18
{TAB}{TAB} 19
{TAB}{TAB} 20
{TAB}{TAB} 21
{TAB}{TAB} 22
{TAB}{TAB} 23 …
woooee 814 Nearly a Posting Maven

Do it in one pass by converting to a dictionary of lists which can then be copied to the file.

test_list = [
    {'item1':3, 'item2':3, 'item3':5},
    {'item1':2, 'item2':6, 'item3':3},
    {'item1':18, 'item2':12, 'item3':1} ]

redone_dict = {}
for dic in test_list:
    for key in dic:
        if key not in redone_dict:
            redone_dict[key] = []
        redone_dict[key].append(dic[key])
print redone_dict
woooee 814 Nearly a Posting Maven

Your indentations are not correct, and you want to do something else if no files are found. And this is the most that I am willing to do to clean up the screwy tabs and spaces in the code so I hope it is legible.

def open_file():
    if '.trv' in os.listdir(os.getcwd()):
    	print "Which trivia episode would you like? It must have a .trv extension:"
    	print os.listdir(os.getcwd())
    	print "Type in the correct file name: "
    	file_name = raw_input()
    	"""Open a file."""
    	try:
                      the_file = open(file_name, 'r')
    	except(IOError), e:
                       print "Unable to open the file", file_name, "Ending program.\n", e
                       raw_input("\n\nPress the enter key to exit.")
                       sys.exit()
    	else:
        	    return the_file
    else:
        print "There are no files in this directory"
        return
woooee 814 Nearly a Posting Maven

The only 'problem' that I see is that you are using the reserved words, 'list' and 'sorted', as variable names, and that you are sorting 'list' and not 'unordered'. Otherwise it looks fine so you will have to be more specific about the problems.

woooee 814 Nearly a Posting Maven

There any many ways to go about it. This uses a list of tuples.

"""
Thanksgiving: 11/ 26 - 11/28 
Winter Recess: 12/24 - 01/16
Martin Luther King's Birthday: 01/18
Presidents' Day: 02/15
Spring Recess: 03/15 - 03/20
Memorial Day: 05/31
Independence Day: 07/05/08
Summer Recess: 08/7 - 9/6
"""
def find_holiday(mm, dd):
                     # month, from_day, to-day, holiday name
    list_of_holidays = [ (11, 26, 28, "Thanksgiving"),
                         (12, 24, 31, "Winter Recess"),
                         (1, 1,   16, "Winter Recess"),
                         (1, 18, 18,  "MLK B'day"),
                         (2, 15, 15,  "Presidents' Day") ]

    for month, from_day, to_day, name in list_of_holidays:
        if (month == mm) and \
           (from_day <= dd <= to_day):
            print("%02d/%02d is %s" % (mm, dd, name)) 
            return

    print("%02d/%02d is not a school holiday" % (mm, dd)) 
    

mm = 12
dd = 25
find_holiday(mm, dd)
mm = 12
dd = 23
find_holiday(mm, dd)
woooee 814 Nearly a Posting Maven

Keying just this into a terminal on my Slackware machine works fine
from wx.glcanvas import *
so it has to be something with the install. Take a look at this link http://www.wxpython.org/download.php I have MESA installed so that may be the difference. You should also try searching the Fedora forum as someone else has probably had this problem.

woooee 814 Nearly a Posting Maven

You can not have wxGTK and wxPython installed at the same time. This bit me a while back. Check to see if wxGTK is installed. Also, check that /usr/bin/python is a symlink to /usr/bin/python2.6 and the same for /usr/lib/python.

woooee 814 Nearly a Posting Maven

Is this correct?
from wxPython.wx import *
In any case, you may have to install/re-install wxPython.

woooee 814 Nearly a Posting Maven

It depends on whether you want to find sub-words or not. The simple example below shows the difference.

words_master = [ "the", "there", "theres"]

##--- look for word in list
word = "there"
if word in words_master:
    print(word, "found")
else:
    print(word, "Not found")

##--- compare each word in the list to the original word
print("-"*30)
for m_word in words_master:
    if m_word in word:
        print("%s found in %s" % (m_word, word))
woooee 814 Nearly a Posting Maven

This line does nothing

if len(modified) == 0 : continue

Look at the second word of the *new* list. If it does not contain
"trunk" or "branches", skip the line. (stuck on this)

Use the "in" keyword.

**---  will return a positive for words like "strunk"
found = False
for word in ["trunk", "branches"] :
    if word in words[1]:
        found = True
if not found:
    print "processing this"
doctorjo5 commented: this is helpful +0
woooee 814 Nearly a Posting Maven

For testing, cut the list down to 10 or 20 hex's and enter a value within that range. You are testing, so you want results in a reasonable amount of time. Also, note that some values are still missing. The following code will print the missing values. It can also be modified to generate the list instead of keying it manually.

charset = [
'01', '02', '03', '04', '05', '06', '07', '08', '09', '0b', '0c', 
'0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', 
'19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', 
'24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', 
'30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3b', 
'3c', '3d', '3e', '41', '42', '43', '44', '45', '46', '47', '48', 
'49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', 
'54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', 
'5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', 
'6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', 
'75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f']

k_range = [ str(x) for x in range(0, 10) ]
k_range.extend(['a', 'b', 'c', 'd', 'e', 'f'])
print k_range
for j in range(0, 8):
    for k in k_range:
        x = str(j) + k
        if x not in charset:
            print x
woooee 814 Nearly a Posting Maven
test_list = \
['<div tal:define="number python: 1">',
'<tal:block repeat="item s_items">',
'    <div tal:define="number python: number + 1">',     
'         <div tal:content="python: number">none</div>',
'     </div>', 
'</tal:block>',
'</div>' ]

found = False
for rec in test_list:
    if rec.strip().startswith("<tal"):
        found = True
    elif rec.strip().startswith("</tal"):
        found = False
    if found:
        print rec
woooee 814 Nearly a Posting Maven

On my machine, Slackware Linux, the message box returns' True' not 1, which may be causing part of the problem. Try the code below and see what it is on your OS. Also, you can just use
if tkMessageBox.askyesno(title='Invitation', message =text):
which would take care of both situations.

import tkMessageBox

def __invitation__( address, name):
    print 'Invitation received'
    text = ('Player "' + name +
            '" on computer ' + address + ' hat sent an invitation \n\nDo you accept it?')
    print text
    result = tkMessageBox.askyesno(title='Invitation', message =text) 
    print("result =", result)
    if result == 1:
        print 'Invitation accepted.'
        
__invitation__('123 Main St.', 'Harry')
woooee 814 Nearly a Posting Maven

If you want to be sure that you only sample the same three values once, then you will have to keep track of the threesome somewhere, as each individual value could be used in another threesome. I don't know how many possible 4 digit permutations, randomly associated in triples there are, but it is a lot and probably would require more computing power than you have. You might want to consider testing for one group of the three at a time. That is, break the value you are testing against into it's component parts and find each one individually. Even better would be testing for the one-twelfth, each hex, individually. That should reduce the time from months to minutes. Finally, note the the "while True" loop never ends.

woooee 814 Nearly a Posting Maven

With some luck your department will publish a list of school holidays and then you can transfer it easily to a list of (month, day) tuples for the year, or the dictionary Gribouillis suggested.

Ah yes. The simplest solution is the best. And there is probably a web page that can be traversed, making it even easier.

woooee 814 Nearly a Posting Maven

There is SpecTcl and VisualPython (3D) as well, but is anyone going to use a 'visual' front end to Tkinter. It is easier to generate your own code IMHO.

woooee 814 Nearly a Posting Maven

What about floating holidays like Easter, (Easter falls on the first Sunday after the first full moon after the spring equinox unless the full moon is on the equinox in which case it is after the following full moon), and Thanksgiving, which is easier but still not a specific date. Also, President's Day is usually celebrated (=some people get it off) on the Monday between Lincoln's and Washington's birthdays. So you will have to allow for some calculations. The simplest to digest would be one dictionary with actual dates, and a second dictionary with known symbols that can be used to calculate the date, 4Th-11 would be the fourth Thursday in November for Thanksgiving. For Easter, you would have to access a web site like NOAA'S to get the equinox and full moon, and that would probably be a separate function so not in any dictionary.

woooee 814 Nearly a Posting Maven

im jus learning how to use the accumulator but i still need sum work lol ...can sum one help me?

First, not too many people are going to take the trouble to translate kiddie-speak into English.

Second, the customary way is to send one number to magic() and have it return True or False. You can then use a loop, or iterate through a custom list, to test more than one number.

woooee 814 Nearly a Posting Maven

Just call 'ps aux' and pipe the output to a file. You can then read the text file and find whatever you want.

woooee 814 Nearly a Posting Maven

I would not support any spammer.

woooee 814 Nearly a Posting Maven

So, we are trying to make this more difficult than it is.

##--- populate a test dictionary
letters = 'HKWZA RRPVQ BIVYS MPDMQ MBUDC'
letters_dict = {}
for ltr in letters:
    if 'A' <= ltr <= 'Z':
        if ltr not in letters_dict:
            letters_dict[ltr] = 0
        letters_dict[ltr] += 1 

print(letters_dict)

## phi = f1 (f1 - 1) + f2 (f2 - 1) + ... + fn (fn - 1)
phi = 0
for ltr in letters_dict:
    qty = letters_dict[ltr]
    phi += qty * (qty-1)
print("Phi =", phi)

keys = letters_dict.keys()
keys.sort()
for ltr in keys:
    print("%s %7.2f" % (ltr, float(letters_dict[ltr])/phi*100))