@-Doing travel kata - any? vs empty? https://stackoverflow.com/questions/6245929/check-for-array-not-empty-any > [nil, 1].any? => true >> [nil, nil].any? => false - Using not in block def dont_give_me_five(start,end_) (start..end_).count { | i | not i.to_s.include? '5' } end - Global $, Class @@ and Instance @ Variables. Never use global because it makes isolating bugs hard. http://www.rubyist.net/~slagell/ruby/globalvars.html https://stackoverflow.com/questions/12358084/whats-difference-between-and-in-a-module module A @@a = 5 end class B include A puts @@a # => 5 end module A @a = 5 end class B include A puts @a # => nil end -Regex cheatsheet http://www.rexegg.com/regex-quickstart.html -Array lessons c = [1,2,3,4] => [1, 2, 3, 4] 2.4.1 :038 > c[0..3] => [1, 2, 3, 4] 2.4.1 :039 > c[0...3] => [1, 2, 3] 2.4.1 :051 > c[0..-2] ...
- Python 2 https://nbviewer.ipython.org/github/jmportilla/Complete-Python-Bootcamp/tree/master/ 3 / 2 = 1 3 / 2.0 = 1.5 float(3) / 2 = 1.5 Another method is using from __future__ import division >>> 3/2 1.5 Python 3 doesn't need to use import - Strings Python 3 from __future__ import print_function print('Hello World') vs Python 2 print 'Hello world' len(' ') checks string length s = 'Hello World' # Grab everything past the first term all the way to the length of s which is len(s) s[1:] => "ello World' # Grab everything UP TO the 3rd index s[:3]=> 'Hel' #Everything s[:] => 'Hello World' # Grab everything, but go in step sizes of 2 s[::2] => 'HloWrd' # We can use this to print a string backwards s[::-1] => 'dlroW olleH' - Python 2 More Strings s = 'STRING' 1. print 'Place another string with a mod and s: %s' %(s) Place anothe...