Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. wordlist = ['cat','dog','rabbit']
  2. [c for c in word for word in wordlist]
  3.  
  4. ['r',
  5. 'r',
  6. 'r',
  7. 'a',
  8. 'a',
  9. 'a',
  10. 'b',
  11. 'b',
  12. 'b',
  13. 'b',
  14. 'b',
  15. 'b',
  16. 'i',
  17. 'i',
  18. 'i',
  19. 't',
  20. 't',
  21. 't']
  22.  
  23. [ch for ch in "".join(wordlist)]
  24.  
  25. [word[i] for word in wordlist for i in range(len(word))]
  26.  
  27. [c for c in word for word in wordlist]
  28.  
  29. [c for word in wordlist for c in word]
  30.  
  31. result = []
  32. for word in wordlist:
  33. for c in word:
  34. result.append(c)
  35.  
  36. In [10]: [c for word in wordlist for c in word]
  37. Out[10]: ['c', 'a', 't', 'd', 'o', 'g', 'r', 'a', 'b', 'b', 'i', 't']
  38.  
  39. In [3]: [c for c in word for word in wordlist]
  40. ---------------------------------------------------------------------------
  41. NameError Traceback (most recent call last)
  42. <ipython-input-7-decfecd23a92> in <module>()
  43. ----> 1 [c for c in word for word in wordlist]
  44.  
  45. NameError: name 'word' is not defined
  46. In [4]: word = 'rabbit'
  47.  
  48. In [5]: [c for c in word for word in wordlist]
  49. Out[5]:
  50. ['r',
  51. 'r',
  52. 'r',
  53. 'a',
  54. 'a',
  55. 'a',
  56. 'b',
  57. 'b',
  58. 'b',
  59. 'b',
  60. 'b',
  61. 'b',
  62. 'i',
  63. 'i',
  64. 'i',
  65. 't',
  66. 't',
  67. 't']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement