Python learning: scrapbook

While browsing my Evernote I found a scrapbook which I have made while learning Python some years back. Thought to share if this helps someone. I am pasting directly (no editing so there might be some spell and grammar mistake).

  • Python 2 division, just use integer part (3/2=1) whereas Python 3 uses real division 3/2 = 1.5
  • Strings in Python are immutable means you can’t change the in-place value of a char. Once string is created you can’t change/replace its elements
  •  s= “Hello World” s[::-1] this will reverse string s “dlroW olleH” double colon is used to tell the range and also how many elements can be skipped
  • if you want to use Python 3 functions in Python 2 then use ‘from __future__ import print_function‘ and similarly other functions 
  • List are mutable but tuples are not mutable (does not support item assignment) aka immutable, fewer methods in tuples then why to use instead of a list? The key is immutability. in a program if you want sequence/Val does not to get changed then tuple is a solution e.g.; storing calendar dates which know will not change during your programs. 
  • Set is a collection of un-ordered unique items it looks like a dictionary (in notation) but only keys which are unique. It can help in removing repeated items means you can use set to cast list.
  • List comprehensive are an excellent way to write clean and efficient code – they are actually de-constructed for loop flatted out in a list
  • Lambda expressions can be used to shorten function this is really useful when used with map(), reduce() and filter() functions
  • First class functions: Treat functions like any other object, we can pass functions, we can return functions, we can assign functions to a variable
  • Closure: Closure takes advantage of first-class functions and returns inner functions and variables local to them.
  • Decorators: It is a function which takes another function as an argument and returns as a function without changing the source code of the original function. Decorator allows easily to add functionality inside our wrapper without modifying original function. 

Note: These are notes for quick reference. If you are serious in learning Python I encourage you to take a book or a tutorial.

Enjoy learning! More to come …

Microsoft Visio and infamous Windings font

Another Microsoft misery 😢 😢

This time, I am struggling to handle the bullets in SVG output of my drawing.  What I found is that  MS Visio still uses windings/symbol fonts to make the bullets. Don’t know why? When are they going to change this and start using standard Unicode chars? Can anyone from MS please explains to me why they don’t believe in standardization?

IMHO Please use Unicode everywhere be it HTML generated from Word or Visio etc. 

Thanks for reading!

IE11 issue with “arrow” and “includes” Javascript method and an alternate solution

Again one more Microsoft problem 😢 😢

Yesterday, I  suddenly observed that one part of my newly developed feature was not working in IE11. This is a simple feature which contains two select boxes, user can select the one or multiple items from the first select box and copy to another select box. I have added a kind of logic there which checks before copying if the item(s) to be copied are already in list 2, if true, alert the user and skip copying duplicates. While developing I checked this feature in chrome, Edge and Firefox and all work perfectly!  I couldn’t check in IE11 and that was my mistake as IE is infamous for such issues. While debugging I saw that IE11 was crashing on the places where I have used the functions  => and .include. Actually, the arrow function is not supported in IE 11. You can refer to this compatibility table: https://kangax.github.io/compat-table/es6/ to get an overview of what is supported where and to what extent in a detailed fashion. You may read more on arrow functions at below link: 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Check below a small demo which shows the problem and an alternate which solves the IE11 issue.

Demo:

**********************************

JSFiddle (Fails in IE11)

JSFiddle (Works in IE11)

**********************************

Github:

code (Fails in IE11) 

code (Works in IE11) 

 

**********************************

Happy coding!