Re: [Tutor] Fwd: Puzzle - Next Step to our interviewing process - Pramati Technologies!

2014-04-15 Thread Ben Finney
Sunil Tech  writes:

> I need the python program

This is a resource for tutoring, not for others to write your program.

Please approach this as an opportunity to do the work yourself *while*
learning. It's still you that needs to write the program.

-- 
 \ “If I held you any closer I would be on the other side of you.” |
  `\ —Groucho Marx |
_o__)  |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Puzzle - Next Step to our interviewing process - Pramati Technologies!

2014-04-15 Thread Walter Prins
Hi,

On 15 April 2014 15:49, Sunil Tech  wrote:
> Hi Danny,
>
>
> Thank you for replying..
>
> I need the python program which takes the attached csv & on running the
> program which will give me the results as


That is still not a question.  It's a requirements statement.  I felt
tempted to point out to you that this is not a freelancer board where
you get to post your software requirements and then we go and develop
your software for you for free, but seeing as you obviously must know
this already and presumably are actually in the process of trying to
learn Python and are presumably using this apparent interview question
as an interesting learning problem, I'll instead ask you to clarify
how far you've gotten and where exactly you're stuck in developing a
solution?  We'll try and help you along and answer specific concrete
questions about problems you're having.  (Please provide code and full
error messages including stack traces where relevant.)

If you're stuck even just getting started, try breaking down the
problem into smaller sub problems and solving them first, for example
it's obvious from the descriptions you'll need to be able to:
a) Interpret command line parameters to pick up the menu file name and
products required
b) Read a/the menu file into memory
c) Perform some sort of search/scan of the list of menu items to
return a list of restaurants carrying all the required items
d) Evaluate the total costs for the items for each of the candidate
restaurants to find the cheapest one
e) Output/Print the result in the required format
Do you have an idea/know how you might tackle each of these sub-tasks?
 If not, do you have an idea where to start looking to learn what you
might use?

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Puzzle - Next Step to our interviewing process - Pramati Technologies!

2014-04-15 Thread Sunil Tech
Hi Danny,


Thank you for replying..

I need the python program which takes the attached csv & on running the
program which will give me the results as


 
Data File data.csv
1, 4.00, burger
1, 8.00, tofu_log
2, 5.00, burger
2, 6.50, tofu_log
 Program Input
program data.csv burger tofu_log
 Expected Output
=> 2, 11.5
---
 
Data File data.csv
3, 4.00, chef_salad
3, 8.00, steak_salad_sandwich
4, 5.00, steak_salad_sandwich
4, 2.50, wine_spritzer

Program Input
program data.csv chef_salad wine_spritzer
Expected Output
=> nil (or null or false or something to indicate that no matching
restaurant could be found)
---
 
Data File data.csv
5, 4.00, extreme_fajita
5, 8.00, fancy_european_water
6, 5.00, fancy_european_water
6, 6.00, extreme_fajita, jalapeno_poppers, extra_salsa
 Program Input
program data.csv fancy_european_water extreme_fajita
 Expected Output
=> 6, 11.0


On Tue, Apr 15, 2014 at 8:05 PM, Danny Yoo  wrote:

> So, what is your question?
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Puzzle - Next Step to our interviewing process - Pramati Technologies!

2014-04-15 Thread Danny Yoo
So, what is your question?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] questions when define a class

2014-04-15 Thread Peter Otten
Qianyun Guo wrote:

> Hi all, I am trying to get a suffix tree from a string. I use three
> classes, Node, Edge, SuffixTree. I have two questions when implementing:
> 
> 【1】
> 
 a = Edge(1,2,3,4)
> 
 a.length
> 
> 1
> if I remove  '@property' in my code, it returns as below:
> 
 a = Edge(1,2,3,4)
> 
 a.length
> 
> 
> 
 a.length()
> 
> 1
> 
> 
> 
> I don't really understand the differences w/ @property, and the
> differences of a.length and a.length(), could you explain?

Properties are a way to calculate attributes:

> @property
> def length(self):
> return self.last_char_index - self.first_char_index

In client code

obj.length

looks like an attribute, but does a calculation under the hood. This is 
particularly useful to keep a changing interface compatible to prior 
versions:

version 1, everybody uses cartesian coordinates:

class Point:
def __init__(self, x, y):
self.x = x
self.y = y

version 2, polar coordinates are so much better ;)

class Point:
def __init__(self, r, phi):
self.r = r
self.phi = phi
@property
def x(self):
return self.r * math.cos(self.phi)
@property
def y(self):
return self.r * math.sin(self.phi)
 
Thanks to properties our new point can be passed to functions that expect 
cartesian coords. Without properties we'd either end up writing a trivial 
wrapper

def get_x(self):
   return self.x

for every attribute (the Java way) and never use attributes directly or we'd 
have to change all occurences of point.x to point.x().

> 【2】
> 
> In SuffixTree, I define two functions, _get_str_from_edge,
> _get_str_from_node, the latter depend on the first one (please see my
> code).  Then I have this problem:
> 
 a = SuffixTree('abcd')
> 
 a._get_str_from_edge(a.edges[(0,1)])
> 
> 'abcd$'
> 
 a._get_str_from_node(0,1)
> 
> TypeError: _get_str_from_edge() takes exactly 2 arguments (3 given)
> 
> Could you tell me what's wrong here?

> def _get_str_from_node(self, source_node_index, dest_node_index):
> return self._get_str_from_edge(self,
> self.edges[(source_node_index,
> \
> dest_node_index)])

self._get_str_from_edge

gives you a "bound method", i. e. one that already knows about self. Invoke 
it as

 return self._get_str_from_edge(
  self.edges[(source_node_index,
  dest_node_index)])

By the way, the backslash is not necessesary as long as there are open 
parens. Preferred:

(1 + # no backslash
2)

Obsolete alternative:
1 + \
2



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] questions when define a class

2014-04-15 Thread Qianyun Guo
Hi all, I am trying to get a suffix tree from a string. I use three
classes, Node, Edge, SuffixTree. I have two questions when implementing:

【1】

>>> a = Edge(1,2,3,4)

>>> a.length

1
if I remove  '@property' in my code, it returns as below:

>>> a = Edge(1,2,3,4)

>>> a.length



>>> a.length()

1



I don't really understand the differences w/ @property, and the differences
of a.length and a.length(), could you explain?

【2】

In SuffixTree, I define two functions, _get_str_from_edge,
_get_str_from_node, the latter depend on the first one (please see my
code).  Then I have this problem:

>>> a = SuffixTree('abcd')

>>> a._get_str_from_edge(a.edges[(0,1)])

'abcd$'

>>> a._get_str_from_node(0,1)

TypeError: _get_str_from_edge() takes exactly 2 arguments (3 given)

Could you tell me what's wrong here?




below is my code, __repr__ are removed for convenience.
###


class Node:

def __init__(self, parent_node):
self.suffix_node = -1
self.parent = parent_node
self.children = []

def add_child(self, child_node_index):
self.children.append(child_node_index)

class Edge:

def __init__(self, first_char_index, last_char_index,\
source_node_index, dest_node_index):
self.first_char_index = first_char_index
self.last_char_index = last_char_index
self.source_node_index = source_node_index
self.dest_node_index = dest_node_index

@property
def length(self):
return self.last_char_index - self.first_char_index

class SuffixTree:

def __init__(self, string):
self.string = string+'$'
self.N = len(self.string)
self.nodes = []
self.num_nodes = 0
self.edges = {}

#initialize two node tree

root = Node(-1)
root.suffix_node = -1
self._add_node(root)

leaf = Node(0)
leaf.suffix_node = 0
self._add_node(leaf)
self.nodes[0].add_child(1)

edge = Edge(0, self.N, 0, 1)
self._add_edge(edge)

def _get_str_from_edge(self, edge):
return self.string[edge.first_char_index : edge.last_char_index]

def _get_str_from_node(self, source_node_index, dest_node_index):
return self._get_str_from_edge(self, self.edges[(source_node_index,
\
dest_node_index)])


def _add_node(self, node):
self.nodes.append(node)
self.num_nodes += 1

def _add_edge(self, edge):
self.edges[(edge.source_node_index, edge.dest_node_index)] = edge
self.nodes[edge.source_node_index].add_child(edge.dest_node_index)
self.nodes[edge.dest_node_index].parent = edge.source_node_index
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quick Question

2014-04-15 Thread Steven D'Aprano
Hi Victoria,

On Tue, Apr 15, 2014 at 12:06:13AM -0500, Victoria Kuritza wrote:

> How can I search in a corpus for three or more occurrences of 
> capitalized words in a line? What would I input as my search?

I'm afraid that question is a bit *too* quick. What are you using for 
search? My guess is that you're using NLTK, but I'm afraid I don't know 
a lot about that. It would help if you showed us what you're using to 
search for a single capitalized word.


Regards,



Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reading a csv file

2014-04-15 Thread Sunil Tech
yes Alan, what you said is true.

Thank you.


On Tue, Apr 15, 2014 at 1:40 PM, Alan Gauld wrote:

> On 15/04/14 07:06, Sunil Tech wrote:
>
>> Hi,
>>
>> #!/usr/bin/python
>>
>> import csv
>> import sys
>>
>> def main():
>>  cr = csv.reader(open("data.csv","rb"))
>>  for row in cr:
>>  print row
>>
>
>  when i run this...
>>
>>
>>  cr = csv.reader(open("data.csv","rb"))
>> AttributeError: 'module' object has no attribute 'reader'
>>
>>
> The most common cause of this error is that you have
> created a file called csv.py which is masking the
> library module.
>
> Could that be the case here?
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quick Question

2014-04-15 Thread Mark Lawrence

On 15/04/2014 06:06, Victoria Kuritza wrote:

How can I search in a corpus for three or more occurrences of
capitalized words in a line? What would I input as my search?


Cheers,

Victoria K.



What does your code currently look like?  What problems are you actually 
having?  Last and by no means least, where is the Python question here?


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


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Quick Question

2014-04-15 Thread Victoria Kuritza
How can I search in a corpus for three or more occurrences of capitalized words 
in a line? What would I input as my search? 


Cheers, 

Victoria K. 






___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python & algorithms (Lang line simplification algorithm)

2014-04-15 Thread Laura Kauria
Okay I'll try. What the main job is to do an algorithm which simples a
line. Algorithm deletes points which are unnecessary accurate according to
tolerance distance user gives.

>> I started by converting the pseudocode I had to python.

Pseudocode:
http://web.cs.sunyit.edu/~poissad/projects/Curve/about_algorithms/lang


   1. function lang(PointList[], Tolerance)
   2. key=0
   3. endP= PointList.length-1
   4. do {
   5. endP= PointList.length-1
   6. if (key+1 != endP) // If there are intermediate points
   7. line= new Line( PointList[key], PointList[endP])
   8. /* Find the point with the furthest perpendicular distance */
   9. maxIndex= key+1
   10. maxD= perpendicularDistance(line, PointList[maxIndex])
   11. for (i=maxIndex+1; i maxD)
   14. maxIndex=i
   15. maxD=d
   16. if (maxD > Tolerance)
   17. endP--;
   18. else
   19. for (i=key+1; i> Still I have problems with perpendicular distance and creating a line
>> with python.

What I mean by creating a line is what Alan answered "checking
distances/intersections
etc only requires the math model." I need the mathematical model not a
picture/graph. I'll try move forward with Bens suggestion of ‘math’ module
which probably help me with both mathematical line model between two points
and its distance between the intermediate points.
> http://docs.python.org/3/library/math.html#trigonometric-functions>.

Here is a picture of the lang algorithm, where you can see distance of
interest by purple
http://psimpl.sourceforge.net/lang.html.

I'll ask later if I can't get this work.

Cheers!





2014-04-15 3:23 GMT+03:00 Ben Finney :

> Laura Kauria  writes:
>
> > Thanks a lot for all the help! I got the courage to start at least..
>
> Congratulations! Courage is a necessary ingredient when starting :-)
>
> Could you please avoid  top-posting, and instead use interleaved style
> https://en.wikipedia.org/wiki/Posting_style#Interleaved_style> for
> your replies, so the conversation is in a natural order.
>
> > I started by converting the pseudocode I had to python.
>
> If it's short and simple, please post it here so we can discuss it in
> context.
>
> > Still I have problems with perpendicular distance and creating a line
> > with python.
> > I need to create a line between two points and then check what is the
> > distance between a line and intermediate points which were between lines
> > start and end point. If someone could help me with this? I could not
> > understand can I do this without math library or not?
>
> The ‘math’ module in the standard library has trigonometric functions
> http://docs.python.org/3/library/math.html#trigonometric-functions>.
> If you have co-ordinate data and know how to use trigonometry, then
> those functions will do what you expect.
>
> --
>  \“If I melt dry ice, can I swim without getting wet?” —Steven |
>   `\Wright |
> _o__)  |
> Ben Finney
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reading a csv file

2014-04-15 Thread Alan Gauld

On 15/04/14 07:06, Sunil Tech wrote:

Hi,

#!/usr/bin/python

import csv
import sys

def main():
 cr = csv.reader(open("data.csv","rb"))
 for row in cr:
 print row



when i run this...

 cr = csv.reader(open("data.csv","rb"))
AttributeError: 'module' object has no attribute 'reader'



The most common cause of this error is that you have
created a file called csv.py which is masking the
library module.

Could that be the case here?


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor