Re: [Tutor] String to list conversion
On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman taylankara...@gmail.comwrote: Hello, I am a beginner. And I am trying to get a user input converted to a list. print 'Enter your first name :' firstname = raw_input() So if the user input is firstname = 'foo'---should become firstlist['f','o','o'] thanks in advance if I understand this correctly, you want a name like foo to be changed to ['f', 'o','o'] This is what the list function does. for example, name = foo list(name) ['f', 'o', 'o'] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد الغزالي No victim has ever been more repressed and alienated than the truth Emad Soliman Nawfal Indiana University, Bloomington http://emnawfal.googlepages.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String to list conversion
On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman taylankara...@gmail.com wrote: Hello, I am a beginner. And I am trying to get a user input converted to a list. print 'Enter your first name :' firstname = raw_input() So if the user input is firstname = 'foo' ---should become firstlist['f','o','o'] Strings behave as sequences of characters, so you can just do firstname = 'foo' firstlist = list(firstname) If you just want to iterate over the letters, there is no need to create a separate list, you can iterate over the string directly, e.g. for letter in firstname: print letter Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String to list conversion
Or, you could do: In [1]: print list(raw_input('name please...')) name please...John ['J', 'o', 'h', 'n'] Robert Berman Kent Johnson wrote: On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman taylankara...@gmail.com wrote: Hello, I am a beginner. And I am trying to get a user input converted to a list. print 'Enter your first name :' firstname = raw_input() So if the user input is firstname = 'foo' ---should become firstlist['f','o','o'] Strings behave as sequences of characters, so you can just do firstname = 'foo' firstlist = list(firstname) If you just want to iterate over the letters, there is no need to create a separate list, you can iterate over the string directly, e.g. for letter in firstname: print letter Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String to list conversion
name like foo to be changed Nitpick: foo is a string, not a name... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor