Hii,
Can anyone provide me the python code for finding a number that is stored in a file .
The file contains 1 lakh numbers!!
And i want a python code that searches the file and find the desired element!!!!
Both linear search and binary search!!
i'm a python beginner!!!!
Plzz help urgent
victorkvarghese 0 Newbie Poster
Recommended Answers
Jump to PostI always learn new things. 1 lakh = 10**5
This is the recommended approach to open a file and handle it since python 2.7:
with open("filename") as f: <handle content of the file>
Otherwise rrashkin's solution is good for linear search.
You say binary search in …
Jump to Post@slate (not to hijack the post but...)
Why? I've seen that construction but why is it preferred?Two reasons:
- It handles the file closing for you
- You can see on the code where you handle the opened file object. No need to look the space between open and …
All 7 Replies
rrashkin 41 Junior Poster in Training
slate 241 Posting Whiz in Training
rrashkin 41 Junior Poster in Training
victorkvarghese 0 Newbie Poster
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
victorkvarghese 0 Newbie Poster
slate 241 Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.