On 06/20/2012 07:05 PM, Mike Nickey wrote:
> Hey all,
>
> I'm working through the google classes to increase my python
> understanding and I'm stuck on sorting tuples.
> What is being asked is to sort tuples based on the second element of
> the tuple in ascending order.
>
> Given a list of non-empt
Mike Nickey wrote:
While i'm still not sure what lamda is or represents, I've found a solution.
Unfortunately, you haven't. It's only by accident that your not-quite-solution
gives the correct value for the example data.
Try it with this data instead:
[(1, 7), (1, 3), (3, 4, 8), (2, 2)]
re
On 21/06/12 00:27, Mike Nickey wrote:
While i'm still not sure what lamda is or represents,
lambda is a function without a name.
def sort_last(tuples):
# +++your code here+++
print sorted(tuples, key=lamda tuples: tuples[-1])
return
The lamda above is identical to doing:
def f(
While i'm still not sure what lamda is or represents, I've found a solution.
Thank you all for your assistance, past, present and future. :)
This seems to work:
def sort_last(tuples):
return sorted(tuples, key=myDef)
def myDef(s):
return s[-1]
On Wed, Jun 20, 2012 at 4:05 PM, Mike Nicke
Hey all,
I'm working through the google classes to increase my python
understanding and I'm stuck on sorting tuples.
What is being asked is to sort tuples based on the second element of
the tuple in ascending order.
Given a list of non-empty tuples, return a list sorted in increasing
order by the
Please do not top post.
> Sorry for the double-post.
>
> I don't think I am wrong either. Replace doesn't return a list of words in
> the way that my code sample was setup to do.
> How would you solve it with replace? Maybe an example prove the point
> better.
>
> -Mario
> On Wed, Jun 20, 2012 a
Sorry for the double-post.
I don't think I am wrong either. Replace doesn't return a list of words in
the way that my code sample was setup to do.
How would you solve it with replace? Maybe an example prove the point
better.
-Mario
On Wed, Jun 20, 2012 at 4:10 PM, mariocatch wrote:
> Yes, I me
Yes, I meant split(). Was a typo :)
On Wed, Jun 20, 2012 at 3:56 PM, Prasad, Ramit wrote:
> Please always post back to the list.
>
> > Nope, strip() was intended so we get a list back instead of a string.
> Need
> > the list for iteration down below that.
>
> >> >para = paragraph.strip('.').s
Please always post back to the list.
> Nope, strip() was intended so we get a list back instead of a string. Need
> the list for iteration down below that.
>> >para = paragraph.strip('.').strip(',').strip().split()
>> I think you want replace not strip.
>>
>> See http://docs.python.org/libra
Oğuzhan Öğreden wrote:
Hi,
I have been learning Python and trying little bits of coding for a while.
Recently I tried to have a paragraph and create a list of its words, then
counting those words. Here is the code:
[code snipped]
I can't understand your code! Indentation is messed up badly. I
> para = paragraph.strip('.').strip(',').strip().split()
I think you want replace not strip.
See http://docs.python.org/library/stdtypes.html#string-methods
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216
Here's one way, can surely be optimized:
*paragraph = "This paragraph contains words once, more than once, and
possibly not at all either. Figure that one out. "
para = paragraph.strip('.').strip(',').strip().split()
wordDict = {}
for word in para:
word = word.strip('.').st
On 20/06/12 16:20, Martin A. Brown wrote:
: should have written something like "counting how many times each
: word occured" insted of "counting words".
You might like to try out collections.defaultdict().
Even a standard dict would simplify the code dramatically.
The defaultdict does sui
Hello,
: Sorry, it seems like I was not clear enough in that statement. I
: should have written something like "counting how many times each
: word occured" insted of "counting words".
You might like to try out collections.defaultdict().
import collections
summary = collections.defaul
I think this is more of what you ar looking for:
>>> a = 'this is a list with is repeated twice.'
>>> a
'this is a list with is repeated twice.'
>>> alist = a.strip().split()
>>> alist
['this', 'is', 'a', 'list', 'with', 'is', 'repeated', 'twice.']
>>> var='is'
>>> alist.count(var)
2
>>>
On Wed,
Sorry, it seems like I was not clear enough in that statement. I should
have written something like "counting how many times each word occured"
insted of "counting words".
2012/6/20 mariocatch
> Hello,
>
> Not sure if this is what you're trying to solve, although it sounds like
> it based on you
Hello,
Not sure if this is what you're trying to solve, although it sounds like it
based on your leading statement.
I think what you have is more complicated than it needs to be for something
that simple:
Why not something like this?
*paragraph = """I have been learning Python and trying litt
Hi,
I have been learning Python and trying little bits of coding for a while.
Recently I tried to have a paragraph and create a list of its words, then
counting those words. Here is the code:
import re
>
>
>> a = """Performs the template substitution, returning a new string.
>> mapping is any di
18 matches
Mail list logo