Nested List Comprehension              {{}}Binary SearchPython Programming for Non-ProgramerDepartment of Computer Science...
OutlinesReview list comprehensionAdvance to nested list comprehensionThe concept of binary searchImplementation of binary ...
Review List Comprehension    [expression for name in list if filter]>>> li = [1,2,3,4,5,6,7,8,9,10]>>> [x**2 for x in li i...
Nested List Comprehension  What is nest? list in list, for in for  [[1],                          for x in list1:   [1,3],...
Case 1: List in List                    [[1],                     [1,3],                     [1,3,5],                     ...
Nested List Comprehension  What is nest? list in list, for in for  [[1],                          for x in list1:   [1,3],...
Case 2: For in For                  for x in list1:                    for y in list2:                       #doing sth>>>...
Binary SearchMore effective than Linear searchFor sorted sequence only                                              {{}}  ...
Demo!Show in TA sessionSource code: http://pastie.org/1409772                                            {{}}             ...
It’s your turnFollow the Pseudo-code to build your ownprogram.Ask TA when you encouted a problem.Good luck for final exam!...
Pseudo-Codefunction binarySearch(Sequence, Target):  low <- the beginning index of Sequence  high <- the ending index of S...
The End
Upcoming SlideShare
Loading in …5
×

Nested List Comprehension and Binary Search

1,650 views

Published on

Introduction to:
- Nested List Comprehension
- Binary Search implementation with Python
Python Programming for Non-programmer
Department of Computer Science, NCCU

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,650
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Nested List Comprehension and Binary Search

  1. 1. Nested List Comprehension {{}}Binary SearchPython Programming for Non-ProgramerDepartment of Computer Science, NCCU
  2. 2. OutlinesReview list comprehensionAdvance to nested list comprehensionThe concept of binary searchImplementation of binary searchQ & A (about today or assignment 5) {{}} List Comprehension Binary search
  3. 3. Review List Comprehension [expression for name in list if filter]>>> li = [1,2,3,4,5,6,7,8,9,10]>>> [x**2 for x in li if x%2==0] [4, 16, 36, 64, 100] {{}} List Comprehension Binary search
  4. 4. Nested List Comprehension What is nest? list in list, for in for [[1], for x in list1: [1,3], for y in list2: [1,3,5], #doing sth [1,3,5,7]] {{}} List Comprehension Binary search
  5. 5. Case 1: List in List [[1], [1,3], [1,3,5], [1,3,5,7]][[2*x - 1 for x in range(1,y+1)] for y in [1,2,3,4]] {{}} List Comprehension Binary search
  6. 6. Nested List Comprehension What is nest? list in list, for in for [[1], for x in list1: [1,3], for y in list2: [1,3,5], #doing sth [1,3,5,7]] {{}} List Comprehension Binary search
  7. 7. Case 2: For in For for x in list1: for y in list2: #doing sth>>> list1=[a,b,c,d]>>> list2=[1,2,3,4]>>> [x+y for x in list1 for y in list2][a1, a2, a3, a4, b1, b2, b3, b4,c1, c2, c3, c4, d1, d2, d3, d4] {{}} List Comprehension Binary search
  8. 8. Binary SearchMore effective than Linear searchFor sorted sequence only {{}} List Comprehension Binary search
  9. 9. Demo!Show in TA sessionSource code: http://pastie.org/1409772 {{}} List Comprehension Binary search
  10. 10. It’s your turnFollow the Pseudo-code to build your ownprogram.Ask TA when you encouted a problem.Good luck for final exam! {{}} List Comprehension Binary search
  11. 11. Pseudo-Codefunction binarySearch(Sequence, Target): low <- the beginning index of Sequence high <- the ending index of Sequence WHILE low less than high: mid <- the middle index of Sequence IF the middle value of Seqeunce larger then Target: high <- the middle of Sequence ELSE IF the middle value of Sequence less than Target: low <- the middle of Sequence ELSE: RETURN mid ENDIF ENDWHILE {{}} RETURN False List Comprehension Binary search
  12. 12. The End

×