语言设计问题 [英] language design question
问题描述
我正在将Python与其他一些脚本语言进行比较,并使用一个简单的
anagrams程序作为样本。
我很惊讶一些我没有工作的python功能
期望/希望;这导致了不那么紧凑/富有表现力的节目风格,我想要 - 恢复到像FORTRAN一样的系列作业。
例如,
- 为什么len()不是字符串的成员函数?相反,一个人说len(w)。
- 为什么不排序()返回一个值?
这样就可以了:
key ='''',join(list(word.lower()。strip())。sort())
代替:
key = ...
key.sort()
key = ...
- 另一个功能我假设但它失败了,对于
词典来说是一个不错的默认值,而且更多+ =喜欢操作;
例如:在字典中累计单词 -
dict [key] + = [word]
而不是:
mark [key] = mark.get(key,[])+ [单词]
前者看起来非常直观,更清晰。
我有点习惯Perl的紧凑性和方便的默认值,其中
会这样做:
我的$ key =加入'''',sort(split(//,lc($ word)));
推@@ $ anagrams {$ key}},$ word
我很好奇为什么这些显而易见的便利设施不存在。 :-)
Thansk有任何背景或见解。
最佳,
格雷戈里
Perl非常好,并且
---- ==通过Newsfeeds.Com发布 - 无限制 - 无限制 - 安全Usenet新闻== ----
< a rel =nofollowhref =http://www.newsfeeds.comtarget =_ blank> http://www.newsfeeds.com 世界排名第一的新闻组服务! 120,000多个新闻组
---- =东海岸和西海岸服务器农场 - 通过加密实现全隐私= ----
key = join'''',sort(split(//,lc(
word)));
push @ {
字谜{
I am comparing Python to a few other scripting languages, and used a simple
anagrams program as a sample.
I was surprised ast a few python features that did not work as I would
expect/wish; which caused less compact/expressive program styles that I
wanted - reverting to a FORTRAN like series of assignments.
For example,
- why is len() not a member function of strings? Instead one says len(w).
- Why doesn''t sort() return a value?
This would allow things like:
key = '''',join( list(word.lower().strip()).sort() )
instead:
key = ...
key.sort()
key = ...
- Another feature I assumed but it failed, is a nice default for
dictionaries, and more += like operations;
For example: to acculumate words in a dictionary -
dict[key] += [word]
Instead of:
mark[key] = mark.get(key,[]) + [word]
The former seems very intuitive, and clearer.
I am a bit used to the compactness and convenient defaults of Perl, which
would do this:
my $key = join '''', sort(split(//, lc($word)));
push @{$anagrams{$key}}, $word
I am curious why these "obvious" conveniences are not present. :-)
Thansk for any context or insight.
Best,
Gregory
Perl is great, and
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
key = join '''', sort(split(//, lc(
word)));
push @{
anagrams{
这篇关于语言设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!