import sys\nimport pdb\n\na = [5, 2, 4, 1]\n\nfor i in range(len(a)):\n for j in range(len(a) - 1):\n if a[j] > a[j+1]:\n t = a[j]\n a[j] = a[j+1] \n a[j] = t\n\nprint a \nsys.exit()\n
Run Code Online (Sandbox Code Playgroud)\n\n我刚刚尝试了Python \xe2\x80\x93 中的C 程序,没有该sorted
函数的正常排序。为什么我没有得到排序列表?
我在python中尝试一个hangman代码.为了匹配单词的字符,iam使用索引函数来获取字符的位置.例如:word ='计算机'
user_input = raw_input('Enter a character :') # say 'T; is given here
if user_input in word:
print "\nThe Character %c is present in the word \n" %user_input
word_dict[word.index(user_input)] = user_input
#so the output will looks like
{0: '_', 1: '_', 2: '_', 3: '_', 4: '_', 5: 'T', 6: '_', 7: '_'}
Run Code Online (Sandbox Code Playgroud)
现在,我的问题来自于重复的角色.
# Another example
>>> 'CARTOON'.index('O')
4
Run Code Online (Sandbox Code Playgroud)
对于第二个'O',如何获得其索引.因为我使用了这个'索引'逻辑,所以我希望继续这样做.