line error on no. 7

2015-07-29 Thread ltc.hotspot
Hi Everyone,


I'm writing python code to read a data text file, split the file into a list of 
words using the split(function) and to print the results in alphabetical order.


The raw python code is located at http://tinyurl.com/oua9uqx


The sample data is located at 
http://tinyurl.com/odt9nhe



Desired Output: ['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 
'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 
'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 
'yonder']


There is a line error on no. 7
What is the cause of this error?



Regards,
Hal






Sent from Surface-- 
https://mail.python.org/mailman/listinfo/python-list


String Attribute

2015-07-29 Thread ltc.hotspot



Hi Everyone:


What is the source of the syntax error to the String Attribute?



Go to the following URL links and view a copy of the raw data file code and 
sample data: 


1.) http://tinyurl.com/p2xxxhl
2.) http://tinyurl.com/nclg6pq


Here is the desired output:


stephen.marqu...@uct.ac.za
lo...@media.berkeley.edu




Hal






Sent from Surface-- 
https://mail.python.org/mailman/listinfo/python-list


Help Command Question

2015-07-29 Thread ltc.hotspot
Hi Everyone,


I'm trying to print a command of list options by using the help command in the 
iPython interpreter. Read captured copy of the printout as follows:



'Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 16:44:52) [MSC 
v.
1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.


IPython 3.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org




In [1]: help list
  File "", line 1
help list
^
SyntaxError: invalid syntax.'


Question: What is the correct help command?





Regards,


Hal


Sent from Surface-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Mailbox

2015-07-30 Thread ltc.hotspot
Hi Cameron,

New revision code:


count = 0
fn = raw_input("Enter file name: ")
if len(fn) < 1 : fname = "mbox-short.txt"
for line in fn:
  if 'From' in line.split()[0]: count += 1
print "There are %d lines starting with From" % count
print len(line)
fn = open(fname)
print "There were", count, "lines in the file with From as the first word"




Syntax message produced by iPython interperter:


NameError Traceback (most recent call last)
C:\Users\vm\Desktop\apps\docs\Python\assinment_8_5_v_2.py in ()
  6 print "There are %d lines starting with From" % count
  7 print len(line)
> 8 fn = open(fname)
  9 print "There were", count, "lines in the file with From as the first wor
d"


NameError: name 'fname' is not defined


In [16]:



Question:


Why is fname = "mbox-short.txt" not loading the sample data?


Sample data file is located at  http://www.pythonlearn.com/code/mbox-short.txt


Regards,
Hal






Sent from Surface





From: Cameron Simpson
Sent: ‎Wednesday‎, ‎July‎ ‎29‎, ‎2015 ‎7‎:‎01‎ ‎PM
To: tu...@python.org





On 29Jul2015 21:55, ltc.hots...@gmail.com  wrote:
>I have a second and unrelated question:
>
>I tried to work backward  to see if there is a logic error associated with a 
>variable is being skipped over:
>
>#top of code, initialize variable
>output_list = ["default"]

Curious: why not just make this an empty list: []

[...snip...]
>count = 0
>fname = raw_input("Enter file name: ")
>if len(fname) < 1 : fname = "mbox-short.txt"
>for line in fname:
>line = line.strip()
>if not line.startswith('From '): continue
>line = line.split()
>count = count + 1
>print len(line)
>fh = open(fname)
>print "There were", count, "lines in the file with From as the first word"
[...snip...]

My first observation would be that "count = count + 1" is not inside the loop.  
That means that it fires just once, _after_ the loop. So it will always be 1.

Also, what is the purpose of this line:

  line = line.split()

Cheers,
Cameron Simpson 
___
Tutor maillist  -  tu...@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to rearrange array using Python?

2015-07-30 Thread ltc.hotspot
Hi Mark,



I’m still confused because line 4 reads: fh=open(fname,'r') # Open a new file 
handle, not fn = open(fname)


Can you write down line by line from error to correction? 



Hal






Sent from Surface





From: Mark Lawrence
Sent: ‎Thursday‎, ‎July‎ ‎30‎, ‎2015 ‎3‎:‎21‎ ‎PM
To: python-list@python.org





On 30/07/2015 21:31, Martin Schöön wrote:
> Here is a problem I think I should be able to solve using Python but
> after having searched the internet for the better part of this
> evening my head spins and I would apreciate some guidance.
>
> Disclaimer
>
> My formal programming training happened 35+ years ago and
> initially involved F77 and later Pascal. Python is something
> I have picked up lately and for fun. I don't master Python by any
> stretch of imagination. I know some linear algebra and numerical
> methods but don't practice any of this on a daily basis...
>
> Problem background
>
> I am just back from visiting my sisters and the younger of them
> was busy planning a youth orchestra summer camp. For some reason
> the kids are allowed to wish with whom they want to share rooms
> and my sister spent several evenings placing kids in rooms
> according to these wishes. It struck me that at least some of this
> work could be done by silicon running code.
>
> My thinking so far
>
> I have played around a little with something called DSM
> https://en.wikipedia.org/wiki/Design_structure_matrix
> at work and think entering all wishes into a 2D array
> for further processing and overview should be a good idea.
>
> An added piece of information is the number of and sizes
> of rooms. I want to overlay this on the array and re-shuffle
> until as many of the wishes as possible are fulfilled.
>
> Here is a picture that may help understanding what I am after:
> https://picasaweb.google.com/103341501341482571816/Miscellaneous#6177389865951753330
> In this example I have 25 individuals (each allowed two wishes),
> one 5-bed room, two 4-bed rooms and four 3-bed rooms.
> Wishes are marked by "1" so a wants to sleep in the same room
> as i and n etc. The rooms are shown as light grey squares
> along the diagonal. Scores to the right show how many wishes
> are fulfilled in each room and at the bottom right corner I
> have the total score. The goal is to re-shuffle the array
> to maximize this score.
>
> How do I go about doing that?
>
> Note: This example is worse than the real life problem as
> most kids go to this camp with friends and wishes are
> highly coordinated. I used a random number generator to
> create wishes... The real problem involves some 80 kids.
> There are some more differences but let us leave them out
> for now.
>
> TIA
>
> /Martin
>

I'm not absolutely certain but I think you're into what's known as a 
constraint satisfaction problem, in which case this 
https://pypi.python.org/pypi/python-constraint/1.2 is as good a starting 
point as any.  If I'm wrong we'll soon get told :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

-- 
https://mail.python.org/mailman/listinfo/python-list-- 
https://mail.python.org/mailman/listinfo/python-list


'open' is not defined

2015-07-30 Thread ltc.hotspot





Hi Everyone:




Why is open not defined in the following code:NameError: name 'open' is not 
defined




Code reads as follows:







fname = raw_input("Enter file name: ")
if len(fname) < 1 : fname = "mbox-short.txt"
fh = open(fname)
count = 0
for line in fh:
if not line.startswith('From'): continue
line2 = line.strip()
line3 = line2.split()
line4 = line3[1]
print line4
count = count + 1
print "There were", count, "lines in the file with From as the first word"







Regards,

Hal






Sent from Surface-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'open' is not defined

2015-07-30 Thread ltc.hotspot
Dieter,




Thanks. What about using the append function to remove duplicate outputs 
entered on or thereafter line no. 9, i.e., 



LIST_APPEND(i) Calls list.append(TOS[-i], TOS). Used to implement list 
comprehensions. While the appended value is popped off, the list object remains 
on the stack so that it is available for further iterations of the loop. URL 
link available at 
https://docs.python.org/2.7/library/dis.html?highlight=append%20list#opcode-LIST_APPEND




What is the command line for such an append function?









Hal


Sent from Surface






Sent from Surface





From: dieter
Sent: ‎Thursday‎, ‎July‎ ‎30‎, ‎2015 ‎11‎:‎22‎ ‎PM
To: python-list@python.org





 writes:
> ...
> Why is open not defined in the following code:NameError: name 'open' is not 
> defined
>
> Code reads as follows:
>
> fname = raw_input("Enter file name: ")
> if len(fname) < 1 : fname = "mbox-short.txt"
> fh = open(fname)
> count = 0
> for line in fh:
> if not line.startswith('From'): continue
> line2 = line.strip()
> line3 = line2.split()
> line4 = line3[1]
> print line4
> count = count + 1
> print "There were", count, "lines in the file with From as the first word"

You might execute the code above in a "restricted execution environment"
(one where "__builtins__" is not the typical "__builtin__" module --
that's how "open" (and other builtins) is found).

-- 
https://mail.python.org/mailman/listinfo/python-list-- 
https://mail.python.org/mailman/listinfo/python-list