Advertisement
redwoolwinterhat

1. Intro to Python String Functions 1.7 Splitsville: Part 2

Mar 31st, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. jobSkills = "unix,linux,mac os x lion,windows 7,python,bash,patience"
  2.  
  3.     ## Splittin' the list and printing to show it's unicode:
  4. jobSkillsListSplit = jobSkills.split(",")
  5.  
  6. print "\n We can split the jobSkillsList, but it's still in unicode:"
  7. print jobSkillsListSplit
  8.  
  9.     ## Making the split list of unicode into a list of strings
  10. jobSkillsList= [str(x) for x in jobSkillsListSplit]
  11.  
  12.     ## Printing the String-ified list:
  13. print "\n \n Unsorted List of Strings:"
  14. print jobSkillsList
  15.  
  16.     ## You can pass without sorting the following way, but you can't print a sorted string with ListName.sort()
  17.     ## Try commenting it out to see!!!
  18.  
  19. jobSkillsListSorted = sorted(jobSkillsList)
  20. print "\n Sorted List of Strings:"
  21. print jobSkillsListSorted
  22.  
  23.     ## If you comment out this line it won't pass. Even though the list                      is sorted on line 14.
  24.     ## Comment it out and hit run, you'll see a printed sorted list that was stored in 'jobSkillsListSorted', printed on line 21.
  25. print jobSkillsList.sort()
  26.  
  27.     ## See how there's two 'None's at the bottom of the output? One is from the print statement right above this. The other is from the exercise test code looking for the existence of a sorted list being created by the code, but not printed.
  28.  
  29.     ## The author had a very specific idea of how we wanted it, mylist.sort() vs sorted(mylist) is the whole issue. One method creates a sorted list that you can assign to a new variable, and the other changes the original list.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement