Python 3 range Vs Python 2 range

Python 3 uses iterators for a lot of things where python 2 used lists.The docs give a detailed explanation including the change to range. The advantage is that Python 3 doesn’t need to allocate the memory if you’re using a large range iterator or mapping. For example for i in range(1000000000): print(i) requires a lot … Read more

Range over characters in Python

This is a great use for a custom generator: Python 3: def char_range(c1, c2): “””Generates the characters from `c1` to `c2`, inclusive.””” for c in range(ord(c1), ord(c2)+1): yield chr(c) then: for c in char_range(‘a’, ‘z’): print(c) Python 2: def char_range(c1, c2): “””Generates the characters from `c1` to `c2`, inclusive.””” for c in xrange(ord(c1), ord(c2)+1): yield … Read more

Merging Ranges In C++

What you need to do is: Sort items lexicographically where range key is [r_start,r_end] Iterate the sorted list and check if current item overlaps with next. If it does extend current item to be r[i].start,r[i+1].end, and goto next item. If it doesn’t overlap add current to result list and move to next item. Here is … Read more

How to expose port ranges (like “3000-4000:3000-4000”) in docker-compose.yml file

There is possibly mistake in the syntax you are using. The ports are defined in the next line and after leaving some space. It should work and as specified in the reference. See example below: ports: – “3000” – “3000-3005” – “8000:8000” – “9090-9091:8080-8081” – “49100:22” – “127.0.0.1:8001:8001” – “127.0.0.1:5000-5010:5000-5010” – “6060:6060/udp”

SQLite loop statements?

Apparently the looping construct in SQLite is the WITH RECURSIVE clause. That documentation link has sample count-to-ten code, a Mandelbrot set plotter, and a Sudoku puzzle solver, all in pure SQL. Here’s an SQLite query that computes the Fibonacci sequence to give you a feel for it: sqlite> WITH RECURSIVE …> fibo (curr, next) …> … Read more

How Do I Loop Through a Date Range in Reverse?

Try upto/downto : irb(main):003:0> sd = Date.parse(‘2010-03-01’) => #<Date: 4910513/2,0,2299161> irb(main):004:0> ed = Date.parse(‘2010-03-15’) => #<Date: 4910541/2,0,2299161> irb(main):005:0> sd.upto(ed) { |date| puts date } 2010-03-01 2010-03-02 2010-03-03 2010-03-04 2010-03-05 2010-03-06 2010-03-07 2010-03-08 2010-03-09 2010-03-10 2010-03-11 2010-03-12 2010-03-13 2010-03-14 2010-03-15 => #<Date: 4910513/2,0,2299161> irb(main):006:0> ed.downto(sd) { |date| puts date } 2010-03-15 2010-03-14 2010-03-13 2010-03-12 2010-03-11 2010-03-10 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)