News for hackers. Stuff that matters.
Re:Comprehensions in Python the Jedi way by d0mine on Sunday March 27, 2016 @10:57AM (#11370133)
There is an easier way to convert bits to ASCII, filter spaces and reverse the string:

  >>> n = int(bbs, 2)
  >>> n.to_bytes((n.bit_length() + 7) // 8, 'big').decode()
  's no  i sn e  h  e r  pm o c'
  >>> _.replace(' ', '')[::-1]
  'comprehensions'
http://stackoverflow.com/questions/7396849/convert-binary-to...
Re:Comprehensions in Python the Jedi way by bearfrieze on Sunday March 27, 2016 @02:31PM (#11370934)
I like the replace method. It's a great way of doing the same thing.

I considered using the [::-1] syntax to reverse the list, but decided that there was enough "cute" stuff in the examples already.

Re:Comprehensions in Python the Jedi way by d0mine on Wednesday March 30, 2016 @07:34PM (#11393853)
[::-1] is an idiomatic way to reverse a string in Python that is the obvious way for a habitual user of the language to do it e.g.:

  def palindrome(s):
      return s == s[::-1]
It could be discussed whether ''.join(reversed(s)) is more readable for a novice programmer learning Python. In general, Python prefers words over punctuation.

Also, there are objects that can be reversed() that are not sequences.

http://stackoverflow.com/questions/931092/reverse-a-string-i...

Re:Comprehensions in Python the Jedi way by tyingq on Sunday March 27, 2016 @04:05PM (#11371297)
Another alternative, works on both py2/3, assuming you replace bbs='000... with bbs=b'000...

  import struct

  result=''.join([chr(int(bits,2)) for bits in struct.unpack('8p'*(int(len(bbs)/8)),bbs)])

  print(result.replace(' ','')[::-1])