Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wordlist = ['cat','dog','rabbit']
- [c for c in word for word in wordlist]
- ['r',
- 'r',
- 'r',
- 'a',
- 'a',
- 'a',
- 'b',
- 'b',
- 'b',
- 'b',
- 'b',
- 'b',
- 'i',
- 'i',
- 'i',
- 't',
- 't',
- 't']
- [ch for ch in "".join(wordlist)]
- [word[i] for word in wordlist for i in range(len(word))]
- [c for c in word for word in wordlist]
- [c for word in wordlist for c in word]
- result = []
- for word in wordlist:
- for c in word:
- result.append(c)
- In [10]: [c for word in wordlist for c in word]
- Out[10]: ['c', 'a', 't', 'd', 'o', 'g', 'r', 'a', 'b', 'b', 'i', 't']
- In [3]: [c for c in word for word in wordlist]
- ---------------------------------------------------------------------------
- NameError Traceback (most recent call last)
- <ipython-input-7-decfecd23a92> in <module>()
- ----> 1 [c for c in word for word in wordlist]
- NameError: name 'word' is not defined
- In [4]: word = 'rabbit'
- In [5]: [c for c in word for word in wordlist]
- Out[5]:
- ['r',
- 'r',
- 'r',
- 'a',
- 'a',
- 'a',
- 'b',
- 'b',
- 'b',
- 'b',
- 'b',
- 'b',
- 'i',
- 'i',
- 'i',
- 't',
- 't',
- 't']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement