Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65511
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.04; "subject:' ": 0.07; 'string': 0.09; 'logic': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Help': 0.11; 'def': 0.12; 'wrote': 0.14; 'random': 0.14; 'be:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:[ 30': 0.16; 'subject:object': 0.16; 'variable.': 0.16; 'select': 0.22; 'issue.': 0.22; 'error': 0.23; 'first,': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'fixed': 0.29; 'leave': 0.29; 'subject:list': 0.30; 'second,': 0.31; 'subject::[': 0.31; 'lists': 0.32; 'subject:with': 0.35; 'but': 0.35; 'really': 0.36; 'next': 0.36; "i'll": 0.36; 'should': 0.36; 'list': 0.37; 'subject:]': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'dave': 0.60; 'subject:Can': 0.60; 'break': 0.61; 'you.': 0.62; 'name': 0.63; 'here': 0.66; 'skip:r 30': 0.69 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re:[Solved]Re: Help with TypeError: Can't convert 'list' object to str implicitly |
| Date | Thu, 6 Feb 2014 01:08:38 -0500 (EST) |
| Organization | news.gmane.org |
| References | <6d3d99f8-637f-4249-a696-ab856b1b8682@googlegroups.com> <e45b079f-eb09-4aad-9393-e35f8c33d2d5@googlegroups.com> |
| X-Gmane-NNTP-Posting-Host | dpc6744192085.direcpc.com |
| X-Newsreader | PiaoHong Usenet NewsReaders 1.36 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6436.1391666732.18130.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1391666732 news.xs4all.nl 2957 [2001:888:2000:d::a6]:50832 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:65511 |
Show key headers only | View raw
dave em <daveandem2000@gmail.com> Wrote in message:
>
>
> Fixed the error and am now onto the next issue.
>
> Solution was to return a list (I think) and then break out the components of the list and put in the variable. Here is how we did it:
>
> secretWord = getRandomWord(words)
> print('The secretWord is ' + str(secretWord[0]))
> print('The secretKey is ' + str(secretWord[1]))
> #Change secretWord from a list to a str
> secretWord = secretWord[1]
>
>
> def getRandomWord(wordDict):
> # This function returns a random string from the passed dictionary of lists of strings, and the key also.
> # First, randomly select a key from the dictionary:
> wordKey = random.choice(list(wordDict.keys()))
> print('The wordKey is ' + wordKey)
> # Second, randomly select a word from the key's list in the dictionary:
> wordIndex = random.randint(0, len(wordDict[wordKey]) - 1)
> print('The wordIndex is ' + str(wordIndex))
> print('The word is ' + wordDict[wordKey][wordIndex])
> return [wordDict[wordKey][wordIndex], wordKey]
>
Much better is to change the name of the function to match what
it's really doing. But I'll leave that to you.
Make the return logic look like:
word = [wordDict[wordKey][wordIndex]
return word, wordKey
Then the calling logic should be:
secretWord, key = getRandomSomethings (words)
print('The secretWord is ' + secretWord
print('The secretKey is ' + key
This way a name is not used for contradictory purposes.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help with TypeError: Can't convert 'list' object to str implicitly dave em <daveandem2000@gmail.com> - 2014-02-05 18:21 -0800
[Solved]Re: Help with TypeError: Can't convert 'list' object to str implicitly dave em <daveandem2000@gmail.com> - 2014-02-05 18:49 -0800
Re:[Solved]Re: Help with TypeError: Can't convert 'list' object to str implicitly Dave Angel <davea@davea.name> - 2014-02-06 01:08 -0500
Re: [Solved]Re: Help with TypeError: Can't convert 'list' object to str implicitly Chris Angelico <rosuav@gmail.com> - 2014-02-06 17:23 +1100
csiph-web