Your SlideShare is downloading. ×
0
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Nested List Comprehension and Binary Search

1,240

Published on

Introduction to: …

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,240
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Nested List Comprehension {{}}Binary SearchPython Programming for Non-ProgramerDepartment of Computer Science, NCCU
  • 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. 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. 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. 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. 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. 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. Binary SearchMore effective than Linear searchFor sorted sequence only {{}} List Comprehension Binary search
  • 9. Demo!Show in TA sessionSource code: http://pastie.org/1409772 {{}} List Comprehension Binary search
  • 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. 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. The End

×