[Tutor] FW: python dictionary and loop

Prasad, Ramit ramit.prasad at jpmorgan.com
Thu Mar 1 00:41:29 CET 2012

Please do not top post and also please remember to reply back to the list.

>Okay thanks for clarifying that that code doesn't split anything. I've been playing around a little bit. I think this is closer to what I am trying to do:
>>>>paragraph = 'This is line one\nLet me show you how'
>>>> paragraph.split('\n')
>['This is line one', 'Let me show you how']
>>>> first_sentence,second_sentence = paragraph.split('\n')
>>>> d = {first_sentence:second_sentence}
>>>> d
>{'This is line one': 'Let me show you how'}
># wouldn't the above code capture what I am trying to do as far as split the string 'paragraph' into two sentences and then create a dictionary {d} that will separate the two sentences so that one sentence {first_sentence} represents a key value and the other sentence {second_sentence} represents the value of the key? 

Yes. it does seem to. What is the reason that you want to do this though?
I usually use this when loading some tabular data like from a csv/Excel file. 

Not sure I see the point when done for a 'paragraph'. 


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

More information about the Tutor mailing list