On Oct 16, 5:42 am, "Francesco Guerrieri" <[EMAIL PROTECTED]> wrote: > On 10/16/07, Beema shafreen <[EMAIL PROTECTED]> wrote: > > > > > > > hi everybody, > > I have a file separated by hash: > > as shown below, > > file: > > A#1 > > B#2 > > A#2 > > A#3 > > B#3 > > > I need the result like this: > > A 1#2#3 > > B 2#3 > > > how will generate the result like this from the above file > > can somebody tell me what i have to do...... > > My code: > > fh =open('abc_file','r') > > for line in fh.readlines(): > > data = line.strip().split('#') > > for data[0] in line > > print line > > > I tried but i donot know how to create 1#2#3 in a single line > > regards > > This certainly seems to be a homework assignment :) > You could try if dictionaries or their variants. > There is an example very similar example to the task you are trying to > solve in the documentation available online on the site > docs.python.org > > francesco- Hide quoted text - > > - Show quoted text -
Even if it is homework, I think this is a good post: - the OP posted his code that he had written so far - the OP asked a specific question (how to write "1#2#3"), not just "help! it wont work! fix it for me!" To the OP: If you can get your data into a list of values, ['1', '2', '3'], then use the join method to join them together with a separator string: print "#".join(['1', '2', '3']) gives: 1#2#3 -- Paul -- http://mail.python.org/mailman/listinfo/python-list