Fetching multiple values

Can you let me know how to use dictionary instead of writing in file.

with open(bin+'output.txt', 'w') as inputlist:
    for inp in input.txt:
        inputlist.write("%s" % inp)

HI, it seemed like this was reposted many times, so I removed the duplicates for you.

To get useful help, you’ll probably want to ask a more specific question. What do you want to use a dictionary for, specifically? What is the overall goal here? What are you trying to put in the dictionary (the values), and how do you expect to find things to read them back out of the dictionary (the `keys)? Here’s the official Python tutorial on dictionaries:

Also it isn’t clear what your code is trying to do—it appears to be intending to copy the lines in an input file to an output file, but input.txt is not a valid variable name in Python. Perhaps you meant to open a file with that name? Also, you don’t need to call inputlist.close(), as the point of the with context manager here is to close the file for you. A working, simpler and more efficient example would be (also tweaking the file names to be more descriptive and less confusing, as inputlist is an output file, not an input list:

with open(bin+'output.txt', 'w') as out_file:
    with open("input.txt", "r") as in_file:

To simply copy a file, you should use shutil.copy, but I’m assuming in your real code you want to do something to the input data first, before you write it out.

If you want to store the input file’s contents in a dictionary instead, you’ll want to decide what are your dictionary keys (like the words in a dictionary) and what are your dictionary values (like the definitions the words correspond to). This will depend on the format of your input file, and what you want to do with it. Perhaps we could suggest something if you could explain that, as well as show us a snippit of a few lines from it.