2016年12月21日 星期三

Python - Quick Note


  • Counters
      

  • Loop and remove(/insert) at same time for list (list移除不正確)
       

           ref. doc https://docs.python.org/3/tutorial/controlflow.html 4.2

  • int to str  → str(<數字>)
          
  • str to list → list("<文字>")
         
  • list to str →'', join(<List>)
     
  • reverse list → <List>.reverse()
     

  • reverse string [<begin>:<end>:<step>]
      

  • find max value for list→ max(<List>)
     

  • 確認List是否為空 → if not <List>
      

  • print不換行 → for 2.7 print("name"),   for 3.5 end=''
  • 不要空格workaround → sys.stdout.write('')
  • print int+str →需先將int轉換為str
      


  • print list in range → print A[3] to A[6] (not include A[7])
     
  • range with step
     

  • map, do something to all list member
     

  • operation to 2 list member in same place
       

  • zfill (only support str)
     

  • Binary to Decimal to Hexadecimal
    


  • lambda - simple function display
    

  • filter
    

  • reduce
   



  • Two list to dictionary
         Method 1:
     
         Method 2: