タグ

2012年4月18日のブックマーク (2件)

  • 何段にも深くなるループを絶対に一段で書く方法 - 今川館

    ループの中でループを回す処理は読みにくい 例えば友達が5人いて、サンドイッチが3種類あって、2種類の飲み物を配る処理を作るとします。 こういう場合、for文を何段にもネストするプログラムを書かざるを得ないときがありますよね。 for friend in friends: for sandwich in sandwiches: for drink in drinks: do_something(friend, sandwich, drink) そもそも、こういうプログラムを書く前は、当にそういう処理で正しいのか考えた方がいいですが、とにかくこんなコードは読みにくいです。 ループの中でループを回すプログラムを字下げして書くことが読みにくさに寄与していると思うのですが、pythonだと字下げは必須なので悩ましいものです。 itertools.productを使えば絶対に1段で書ける しかし、こ

    何段にも深くなるループを絶対に一段で書く方法 - 今川館
  • lake.js

    How does it work? Like this: <script src="jquery.js"></script> <script src="lake.js"></script> <script> $(function() { $('#lake-img').lake({ 'speed': 1, 'scale': 0.5, 'waves': 10 }); }); </script> ... <img id="lake-img" src="lake.png" style="display: none;"/> Lake.js takes an img element and inserts a canvas element displaying the image and its flipped reflection directly after the img element. Th