The Zen of Python
1 | Beautiful is better than ugly. |
Easter Egg
1 | >>> import this |
1 | Beautiful is better than ugly. |
1 | >>> import this |
What does the computer industry thrive on apart from anarchy?
Technology trends may push Silicon Valley back to the future. Carver Mead, a pioneer in integrated circuits and a professor of computer science at the California Institute of Technology, notes there are now work-stations that enable engineers to design, test and produce chips right on their desks, much the way an editor creates a newsletter on a Macintosh. As the time and cost of making a chip drop to a few days and a few hundred dollars, engineers may soon be free to let their imaginations soar without being penalized by expensive failures. Mead predicts that inventors will be able to perfect powerful customized chips over a weekend at the office—spawning a new generation of garage start-ups and giving the U.S. a jump on its foreign rivals in getting new products to market fast. ‘We’re got more garages with smart people,’ Mead observes. ‘We really thrive on anarchy.’
And on Asians. Already, orientals and Asian Americans constitute the majority of the engineering staffs at many Valley firms. And Chinese, Korean, Filipino and Indian engineers are graduating in droves from California’s colleges. As the heads of next-generation start-ups, these Asian innovators can draw on customs and languages to forge righter links with crucial Pacific Rim markets. For instance, Alex Au, a Stanford Ph. D. from Hong Kong, has set up a Taiwan factory to challenge Japan’s near lock on the memory-chip market. India-born N.Damodar Reddy’s tiny California company reopened an AT & T chip plant in Kansas City last spring with financing from the state of Missouri. Before it becomes a retirement village, Silicon Valley may prove a classroom for building a global business.
这篇文章写于20世纪末,预见了亚裔人才在科技产业中的重要作用,以及全球化对硅谷发展的影响。
原文: Technology trends may push Silicon Valley back to the future.
翻译: 技术趋势可能会把硅谷推回到未来。
讲解:
原文: Carver Mead, a pioneer in integrated circuits and a professor of computer science at the California Institute of Technology, notes there are now work-stations that enable engineers to design, test and produce chips right on their desks, much the way an editor creates a newsletter on a Macintosh.
翻译: 卡弗·米德,集成电路的先驱、加州理工学院的计算机科学教授,指出现在有些工作站能让工程师在自己的办公桌上设计、测试和生产芯片,就像编辑在苹果电脑上制作通讯稿一样。
讲解:
原文: As the time and cost of making a chip drop to a few days and a few hundred dollars, engineers may soon be free to let their imaginations soar without being penalized by expensive failures.
翻译: 随着制造芯片的时间和成本降到几天和几百美元,工程师们可能很快就能自由地让想象力翱翔,而不会因昂贵的失败而受到惩罚。
讲解:
原文: Mead predicts that inventors will be able to perfect powerful customized chips over a weekend at the office—spawning a new generation of garage start-ups and giving the U.S. a jump on its foreign rivals in getting new products to market fast.
翻译: 米德预测,发明家们将能够在办公室用一个周末的时间完善强大的定制芯片——催生新一代车库创业公司,并使美国在快速将新产品推向市场方面领先于外国竞争对手。
讲解:
原文: ‘We’ve got more garages with smart people,’ Mead observes.
翻译: “我们有更多车库和聪明人,”米德说道。
讲解:
原文: ‘We really thrive on anarchy.’
翻译: “我们真的在无序状态中茁壮成长。”
讲解:
原文: And on Asians.
翻译: 还有(依靠)亚洲人。
讲解:
原文: Already, orientals and Asian Americans constitute the majority of the engineering staffs at many Valley firms.
翻译: 东方人和亚裔美国人已经构成了硅谷许多公司工程团队的大多数。
讲解:
原文: And Chinese, Korean, Filipino and Indian engineers are graduating in droves from California’s colleges.
翻译: 而且中国、韩国、菲律宾和印度的工程师正成群结队地从加州的大学毕业。
讲解:
原文: As the heads of next-generation start-ups, these Asian innovators can draw on customs and languages to forge tighter links with crucial Pacific Rim markets.
翻译: 作为下一代创业公司的领导者,这些亚洲创新者可以利用习俗和语言与至关重要的环太平洋市场建立更紧密的联系。
讲解:
原文: For instance, Alex Au, a Stanford Ph.D. from Hong Kong, has set up a Taiwan factory to challenge Japan’s near lock on the memory-chip market.
翻译: 例如,来自香港的斯坦福博士 Alex Au 在台湾建立了一家工厂,挑战日本对内存芯片市场近乎垄断的地位。
讲解:
原文: India-born N. Damodar Reddy’s tiny California company reopened an AT&T chip plant in Kansas City last spring with financing from the state of Missouri.
翻译: 出生于印度的 N. Damodar Reddy 的加州小公司去年春天在密苏里州的资助下,重新开放了 AT&T 在堪萨斯城的芯片工厂。
讲解:
原文: Before it becomes a retirement village, Silicon Valley may prove a classroom for building a global business.
翻译: 在成为退休村之前,硅谷可能会成为建立全球业务的课堂。
讲解:
深层含义: 作者暗示硅谷如果不利用好亚裔人才和全球化机遇,可能会衰落;但如果把握住机会,就能成为全球商业的典范。
What important thing did King Alfred learn when he penetrated the Danish camp of Guthrum?
Alfred the Great acted his own spy, visiting Danish camps disguised as a minstrel. In those days wandering minstrels were welcome everywhere. They were not fighting men, and their harp was their passport. Alfred had learned many of their ballads in his youth, and could vary his programme with acrobatic tricks and simple conjuring.
While Alfred’s little army slowly began to gather at Athelney, the king himself set out to penetrate the camp of Guthrum, the commander of the Danish invaders. There had settled down for the winter at Chippenham: thither Alfred went. He noticed at once that discipline was slack: the Danes had the self-confidence of conquerors, and their security precautions were casual. They lived well, on the proceeds of raids on neighbouring regions. There they collected women as well as food and drink, and a life of ease had made them soft.
What makes trading between rich countries difficult?
Chickens slaughtered in the United States, claim officials in Brussels, are not fit to grace European tables. No, say the American: our fowl are fine, we simply clean them in a different way. These days, it is differences in national regulations, far more than tariffs, that put sand in the wheels of trade between rich countries. It is not just farmers who are complaining. An electric razor that meets the European Union’s safety standards must be approved by American testers before it can be sold in the United States, and an American-made dialysis machine needs the EU’s okay before is hits the market in Europe.
As it happens, a razor that is safe in Europe is unlikely to electrocute Americans. So, ask businesses on both sides of the Atlantic, why have two lots of tests where one would do? Politicians agree, in principle, so America and the EU have been trying to reach a deal which would eliminate the need to double-test many products. They hope to finish in time for a trade summit between America and the EU on May 28TH. Although negotiators are optimistic, the details are complex enough that they may be hard-pressed to get a deal at all.
Why? One difficulty is to construct the agreements. The Americans would happily reach one accord on standards for medical devices and then hammer out different pacts covering, say, electronic goods and drug manufacturing. The EU—following fine continental traditions—wants agreement on general principles, which could be applied to many types of products and perhaps extended to other countries.
In what way does echo-location in bats play an utilitarian role?
Not all sounds made by animals serve as language, and we have only to turn to that extraordinary discovery of echo-location in bats to see a case in which the voice plays a strictly utilitarian role.
To get a full appreciation of what this means we must turn first to some recent human inventions. Everyone knows that if he shouts in the vicinity of a wall or a mountainside, an echo will come back. The further off this solid obstruction, the longer time will elapse for the return of the echo. A sound made by tapping on the hull of a ship will be reflected from the sea bottom, and by measuring the time interval between the taps and the receipt of the echoes, the depth of the sea at that point can be calculated. So was born the echo-sounding apparatus, now in general use in ships. Every solid object will reflect a sound, varying according to the size and nature of the object. A shoal of fish will do this. So it is a comparatively simple step from locating the sea bottom to locating a shoal of fish. With experience, and with improved apparatus, it is now possible not only to locate a shoal but to tell if it is herring, cod, or other well-known fish, by the pattern of its echo.
It has been found that certain bats emit squeaks and by receiving the echoes, they can locate and steer clear of obstacles—or locate flying insects on which they feed. This echo-location in bats is often compared with radar, the principle of which is similar.
原文:
Not all sounds made by animals serve as language, and we have only to turn to that extraordinary discovery of echo-location in bats to see a case in which the voice plays a strictly utilitarian role.
结构分析:
1 | 主句1: Not all sounds ... serve as language |
逐词翻译:
参考译文:
并非所有动物发出的声音都具有语言功能,我们只需看看蝙蝠回声定位这一非凡发现,就能明白声音在某些情况下纯粹起着实用性作用。
翻译要点:
原文:
Everyone knows that if he shouts in the vicinity of a wall or a mountainside, an echo will come back.
结构分析:
1 | 主句: Everyone knows that... |
逐词翻译:
参考译文:
每个人都知道,如果在墙壁或山坡附近大喊,就会听到回声返回。
原文:
A sound made by tapping on the hull of a ship will be reflected from the sea bottom, and by measuring the time interval between the taps and the receipt of the echoes, the depth of the sea at that point can be calculated.
结构分析:
1 | 第一部分: |
逐词翻译:
参考译文:
敲击船体发出的声音会从海底反射回来,通过测量敲击声和接收回声之间的时间间隔,就可以计算出该处的海水深度。
翻译技巧:
原文:
So was born the echo-sounding apparatus, now in general use in ships.
结构分析:
1 | 倒装句: So was born the apparatus |
逐词翻译:
参考译文:
回声测深仪就这样诞生了,现在已在船舶上普遍使用。
语法点:
原文:
Every solid object will reflect a sound, varying according to the size and nature of the object.
结构分析:
1 | 主句: Every solid object will reflect a sound |
逐词翻译:
参考译文:
每个固体物体都会反射声音,反射效果因物体的大小和性质而异。
翻译技巧:
原文:
So it is a comparatively simple step from locating the sea bottom to locating a shoal of fish.
结构分析:
1 | 主语: it (形式主语) |
逐词翻译:
参考译文:
因此,从定位海底到定位鱼群,这是一个相对简单的进步。
原文:
With experience, and with improved apparatus, it is now possible not only to locate a shoal but to tell if it is herring, cod, or other well-known fish, by the pattern of its echo.
结构分析:
1 | 状语1: With experience |
逐词翻译:
参考译文:
凭借经验和改进的设备,现在不仅可以定位鱼群,还可以通过回声的模式来判断是鲱鱼、鳕鱼还是其他常见鱼类。
翻译难点:
原文:
It has been found that certain bats emit squeaks and by receiving the echoes, they can locate and steer clear of obstacles—or locate flying insects on which they feed.
结构分析:
1 | 主句: It has been found that... |
逐词翻译:
参考译文:
研究发现,某些蝙蝠会发出尖叫声,通过接收回声,它们可以定位并避开障碍物——或者定位它们捕食的飞行昆虫。
翻译要点:
原文:
This echo-location in bats is often compared with radar, the principle of which is similar.
结构分析:
1 | 主句: This echo-location is compared with radar |
逐词翻译:
参考译文:
蝙蝠的这种回声定位常被拿来与雷达相比较,两者的原理相似。
| 技巧 | 例句 | 说明 |
|---|---|---|
| 部分否定 | Not all sounds | 译为”并非所有”而非”所有都不” |
| 后置定语前置 | sounds made by animals | 译为”动物发出的声音” |
| 倒装句还原 | So was born… | 强调”诞生”,译时可还原语序 |
| 分词短语处理 | varying according to | 译为”因…而异” |
| 形式主语转换 | it is possible to… | 可直接译为”可以…” |
How does the writer describe sport at the international level?
I am always amazed when I hear people saying that sport create goodwill between nations, and that if only the common peoples of the world could meet one another at football or cricket, they would have no inclination to meet on the battle field. Even if one didn’t know from concrete examples (the 1936 Olympic Games, for instance) that international sporting contests lead to orgies of hatred, one could deduce it from general principles.
Nearly all the sports practised nowadays are competitive. You play to win, and the game has little meaning unless you do your utmost to win. On the village green, where you pick up sides and no feeling of local patriotism is involved, it is possible to play simply for the fun and exercise: but as soon as the question of prestige arises, as soon as you feel that you and some larger unit will be disgraced if you lose, the most savage combative instincts are aroused. Anyone who has played even in a school football match knows this. At the international level, sport is frankly mimic warfare. But the significant thing is not the behavior of the players but the attitude of the spectators; and, behind the spectators, of the nations who work themselves into feries over these absurd contests, and seriously believe—at any rate for short periods—that running, jumping and kicking a ball are tests of national virtue.
I am always amazed when I hear people saying that sport create goodwill between nations, and that if only the common peoples of the world could meet one another at football or cricket, they would have no inclination to meet on the battle field.
每当我听到人们说体育能在国家之间创造友好关系,说如果世界各国的普通民众能在足球场或板球场上相遇,他们就不会有意愿在战场上相见时,我总是感到惊讶。
Even if one didn’t know from concrete examples (the 1936 Olympic Games, for instance) that international sporting contests lead to orgies of hatred, one could deduce it from general principles.
即使人们不知道具体的例子(比如1936年奥运会),不知道国际体育比赛会导致仇恨的狂欢,也可以从一般原理中推断出这一点。
Nearly all the sports practised nowadays are competitive. You play to win, and the game has little meaning unless you do your utmost to win.
如今实行的几乎所有体育运动都是竞技性的。你参赛是为了获胜,除非你全力以赴去赢,否则比赛就没什么意义。
On the village green, where you pick up sides and no feeling of local patriotism is involved, it is possible to play simply for the fun and exercise:
在乡村草地上,你随意分组,不涉及任何地方爱国主义情感时,确实可能只是为了娱乐和锻炼而比赛:
but as soon as the question of prestige arises, as soon as you feel that you and some larger unit will be disgraced if you lose, the most savage combative instincts are aroused.
但一旦涉及声誉问题,一旦你感到如果输了,你和你所代表的某个更大群体将蒙受耻辱,最野蛮的好斗本能就会被激发出来。
Anyone who has played even in a school football match knows this.
任何参加过哪怕只是校园足球比赛的人都知道这一点。
At the international level, sport is frankly mimic warfare.
在国际层面,体育坦率地说就是模拟战争。
But the significant thing is not the behavior of the players but the attitude of the spectators;
但重要的不是运动员的行为,而是观众的态度;
and, behind the spectators, of the nations who work themselves into furies over these absurd contests,
而在观众背后,是那些为这些荒谬的竞赛让自己陷入狂怒的国家,
and seriously believe—at any rate for short periods—that running, jumping and kicking a ball are tests of national virtue.
并且认真地相信——至少在短时间内——跑步、跳跃和踢球是对民族美德的考验。
1 | 理想观点:体育促进和平 |
| 表面 | 深层 |
|---|---|
| 体育比赛 | 民族主义 |
| 观众狂热 | 集体非理性 |
| 竞技精神 | 战争思维 |
I am always amazed when…
as soon as… the most savage instincts are aroused
frankly speaking / to be frank
work oneself into…
总结:这是一篇犀利的批判性散文,作者通过层层递进的论证,揭示了国际体育背后的民族主义本质,文笔辛辣,论证有力,是经典的议论文范本。🎯
How does the writer like to treat young people?
People are always talking about ‘the problem of youth’. If there is one — which I take leave to doubt — then it is older people who create it, not the young themselves. Let us get down to fundamentals and agree that the young are after all human beings — people just like their elders. There is only one difference between an old man and a young one: the young man has a glorious future before him and the old one has a splendid future behind him: and maybe that is where the rub is.
When I was a teenager, I felt that I was just young and uncertain — that I was a new boy in a huge school, and I would have been very pleased to be regarded as something so interesting as a problem. For one thing, being a problem gives you a certain identity, and that is one of the things the young are busily engaged in seeking.
I find young people exciting. They have an air of freedom, and they have not a dreary commitment to mean ambitions or love of comfort. They are not anxious social climbers, and they have no devotion to material things. All this seems to me to link them with life, and the origins of things. It’s as if they were, in some sense, cosmic beings in violent and lovely contrast with us suburban creatures. All that is in my mind when I meet a young person. He may be conceited, ill-mannered, presumptuous or fatuous, but I do not turn for protection to dreary cliches about respect for elders — as if mere age were a reason for respsect. I accept that we are equal, and I will argue with him, as an equal, if I think he is wrong.
1 | 引言:驳斥"青年问题" |
“People are always talking about ‘the problem of youth’. If there is one—which I take leave to doubt—then it is older people who create it, not the young themselves.”
解析:
“Let us get down to fundamentals and agree that the young are after all human beings—people just like their elders.”
解析:
“There is only one difference between an old man and a young one: the young man has a glorious future before him and the old one has a splendid future behind him: and maybe that is where the rub is.”
解析:
“When I was a teenager, I felt that I was just young and uncertain—that I was a new boy in a huge school…”
解析:
“…and I would have been very pleased to be regarded as something so interesting as a problem.”
解析:
“For one thing, being a problem gives you a certain identity, and that is one of the things the young are busily engaged in seeking.”
解析:
“I find young people exciting.”
解析:
“They have an air of freedom, and they have not a dreary commitment to mean ambitions or love of comfort.”
解析:
“They are not anxious social climbers, and they have no devotion to material things.”
解析:
“All this seems to me to link them with life, and the origins of things.”
解析:
“It’s as if they were, in some sense, cosmic beings in violent and lovely contrast with us suburban creatures.”
解析:
| 年轻人 | 老年人 |
|---|---|
| cosmic beings(宇宙生命) | suburban creatures(郊区生物) |
| 广阔、自由、本真 | 狭隘、世俗、平庸 |
violent and lovely contrast = 激烈而美好的对比
suburban 的隐喻:
“All that is in my mind when I meet a young person.”
解析:
“He may be conceited, ill-mannered, presumptuous or fatuous…”
解析:
“…but I do not turn for protection to dreary clichés about respect for elders—as if mere age were a reason for respect.”
解析:
核心观点: 年龄本身不值得尊重,值得尊重的是人品和智慧
“I accept that we are equals, and I will argue with him, as an equal, if I think he is wrong.”
解析:
三次强调”equal”(平等):
argue 的积极含义:
| 对比项 | 年轻人 | 老年人 |
|---|---|---|
| 时间维度 | 未来在前 | 过去在后 |
| 生活态度 | 自由、理想主义 | 功利、物质主义 |
| 存在状态 | 宇宙生命 | 郊区生物 |
| 对比效果 | violent & lovely | dreary & mean |
“It is older people who create it, not the young themselves.”
“Being a problem gives you a certain identity.”
“As if mere age were a reason for respect.”
“Cosmic beings in violent and lovely contrast with suburban creatures.”
这篇文章是一篇关于代际关系的哲理散文,作者通过:
最终传达的核心价值观:
真正的尊重不是基于年龄,而是基于平等的人格;年轻人的价值不在于完美,而在于生命力和可能性。
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Easy
采用递归的方法。如果root为空,则直接返回root; 如果root的值<L,表示root及其左子树所有节点都<L,那么需要改变root节点,从root.right中重新寻找root节点。同理,当root的值>R时,需要从root.left中重新寻找root节点。当L<=root.val<=R时,则递归处理root的左右子树。
1 | class TreeNode(object): |
晚上11点前睡,你能做到吗?
前几天,北京大学法学院2017迎新典礼上,白建军教授给新生的建议火遍全网:“早睡早起+把微信朋友圈控制在10人以内+拒绝以陪读为目的的表白。这个办法能不能把你弄成精英中的精英,我不知道。但试过的,都说好。”
这3条建议中,我试过“早睡早起”这一条。抓住早睡这个突破点后,早起也能轻松上手,投资小,回报大,性价比高。
但我观察周围,这大约是个年轻人全民熬夜的年代。有人工作分工没办法,有人夜晚干活效率高,有人单纯性晚睡拖延症。许多人在睡觉方面缺乏自制力,晚上不想睡,手机像长在手上似的;早上起不来,醒来就跟闹钟置气,一天到晚觉得困。
原来在我们这个时代,早睡早起,真的变成了最知易行难的自律。
虽然网上不时会曝出因为熬夜导致健康受损甚至猝死的案例,不管当事人如何苦口婆心地劝诫一定要规律作息,千万不要熬夜,可还是有许多人会说,道理我们都知道的,可就是忍不住熬夜啊。
以前我在深圳工作时,有段时间早上五点多就起床,去附近的荔香公园快走。我发现这个时段公园里老年人的密度极高,他们神采奕奕地进行着做操、跑步、挥鞭等各种锻炼。
而我看到年轻人密度最高的时段是晚上。我有时加班到晚上十点多,在赶回家睡觉的路上,看到写字楼里还有大片灯光,商场周围还有K歌聚会,便利店里还有人进人出。
这好像一幕滑稽戏,早睡早起的老年人和晚睡晚起的年轻人,处于不同的时区。结果,老年人状态越来越燃,年轻人却越活越没精神。
其实,早睡早起,是性价比最高的自律。
前东家大领导30多岁那年,大病一场之后,作息习惯大换血,他把工作模式从没日没夜改为早睡早起,工作绩效不减反增;
我婶婶婚后越长越好看,随着年纪增长,她的皮肤却比初见时细腻白嫩了很多,她说因为自己单身时熬的夜,结婚后都戒了;
我早上五点多去公园的事迹被同事们听说后,都叉着腰笑我过着老年人的生活,可我那时的工作效率和身体状态都处于巅峰级别。
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.
The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are R(Right), L(Left), U(Up) and D(down). The output should be true or false representing whether the robot makes a circle.
Example 1:
1 | Input: "UD" |
Example 2:
1 | Input: "LL" |
Easy
对每个方向计数,如果L出现的次数==R出现的次数,并且U出现的次数==D出现的次数,则robot会回到初始位置,返回True;否则返回False
1 | class Solution(object): |