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 Post100000 isn't that big. Why not just:
f=open(<your text file>) for line in f: if <your search string> in line: <do your thing> f.close()
or even:
f=open(<your text file>) strA=f.read() f.close() if <your search string> in strA: <do your thing>
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 …
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.