Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Only in python! (http://www.programmingforums.org/showthread.php?t=7612)

Jessehk Dec 16th, 2005 9:43 PM

Only in python!
 
Only in python could I do things like:

:


for word in "This is a sentence".split():
    print word


or

:


numbs = range(10)

def kid(x):
    if x < 8:
          return x

for x in filter(mature, numbs):
    print x


or even

:


people = {"Bob":20, "Joe":25, "Anne":10}

for a, b in dict([(name, age) for name, age in people.items() if age > 15]).items():
    print a, b


I just feel like I am cheating.
Yes, the features in python are fantastic, but I somehow get more satisfaction from implementing it myself. Am I the only one?

MicDareall Dec 16th, 2005 10:50 PM

Yes and No......... I feel real satisfaction from writing an assembly language program too .... but I would still much rather create projects with C\C+ then that..... and I would much rather create projects with Python then C\C+ for the same reasons..... I still get satisfaction from it....either way,,

coldDeath Dec 17th, 2005 3:05 AM

Its not cheating, these are pythons features man :-)

These are the things that i love about python. But the higher the level of your programming the language, the more cool stuff like this are included. (IME)

Master Dec 17th, 2005 10:31 AM

you are not cheating, you can do that too in ruby.

Riddle Dec 17th, 2005 10:53 AM

>>Master
Does that make it any less.. cheatlike?

I don't think it's cheating, or lame; the built-in functions are included for a reason. The reason? To be used. :P

This is cheating, in my opinion.

Cerulean Dec 17th, 2005 12:11 PM

:

for a, b in dict([(name, age) for name, age in people.items() if age > 15].items():
Converting to dict and then calling items does exactly the same thing to the list as not having done so, unless you're trying to remove duplicate entries.

And you think these features are cool and make life too easy? Try reading webpages, writing/reading CSV files, dumping/loading objects from files, and using db files in C++ or C or even PHP or Perl.

Jessehk Dec 17th, 2005 12:34 PM

Quote:

Originally Posted by Cerulean
:

for a, b in dict([(name, age) for name, age in people.items() if age > 15].items():
Converting to dict and then calling items does exactly the same thing to the list as not having done so, unless you're trying to remove duplicate entries.

And you think these features are cool and make life too easy? Try reading webpages, writing/reading CSV files, dumping/loading objects from files, and using db files in C++ or C or even PHP or Perl.


Ya, I caught the pointless conversion to a dict and then to a list of tuples. Unfortunately, the edit button dissapeared. There is also an error the second code snippet where I define a kid() function and then call mature() with filter(). The specific examples are really not the point of the thread.

Dietrich Dec 17th, 2005 12:45 PM

Quote:

Ya, I caught the pointless conversion to a dict and then to a list of tuples. Unfortunately, the edit button dissapeared. There is also an error the second code snippet where I define a kid() function and then call mature() with filter(). The specific examples are really not the point of the thread.
You were all excited about Python and made a few booboos. We forgive you! Python is something to be excited about! The language is much more modular than C++, so let's use those highly optimized modules.

Klipt Dec 17th, 2005 5:11 PM

It's hardly a case of 'only in Python' - more like 'only in high level languages'. The filter function you like so much is a functional programming feature which Lisp had fifty years ago. And with the right kind of libraries you can do a lot of those things in C++ or Java too.

Using a library isn't cheating if your goal is to write a program to do something which the library would make easier. It's only cheating if your goal is to learn how to write such code and understand how it works yourself. So long as you don't cheat yourself, I wouldn't worry. Or would you rather write everything in machine code? (Not even assembler, I'm talking about using hex code instead of mnemonics like ADD and MOV! :p)

DaWei Dec 17th, 2005 5:34 PM

Quote:

The filter function you like so much is a functional programming feature which Lisp had fifty years ago
Your "facts" are bullshit, despite the position of Lisp as a seminal language. ('Seminal language' is my personal opinion.) Fifty years ago was 1955. List processing was being introduced (hopefully) into Fortran at that time. Possibly you're thinking of IPL. In 1956, John McCarthy began to develop the concepts behind what would become Lisp. Inaccurate souces will perhaps credit him with inventing it as early as 1958. The first complete compiler appeared in the early 60's. OO concepts were incorporated in Lisp in the 80's.


All times are GMT -5. The time now is 8:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC