Find the unique number

kata排名第一的答案

function findUniq(arr)

 { 

//sort:数组排序函数 更改原数组 传入一个函数

  • 若 a 小于 b,在排序后的数组中 a 应该出现在 b 之前,则返回一个小于 0 的值。
  • 若 a 等于 b,则返回 0。
  • 若 a 大于 b,则返回一个大于 0 的值。

  arr.sort((a,b)=>a-b);//按照从小到大排序

  

return arr[0]==arr[1]? arr.pop():arr[0]

//arr.pop()删除最后一名数组并返回删除的值

  //如果排第一的值等于第二的值则证明正确答案在最后返回最后的值 反之第一个是正确答案

}

用python实现以下需求,并输出代码。a) Read “train.csv” data to your Python session. b) Check the dimension of the dataframe that you created in a). (How many number of rows and columns do you observe in the dataframe?) And print the column names of the dataframe. c) We want to find out the most common word in articles of class 2 (articles on stock price movement). Please do the following to solve this question. • Step 1. Create a variable named “combinedText” having an empty string (“”) value • Step 2. Define a variable “news” in a for loop to iterate over the articles of class 2 (df.news[df.label==2]) – Step 3. Add “combinedText” to “news” (we need to place an empty space (“ ”) in between them) and assign the resultant string back to “combinedText” • Step 4. Split “news” into words (you can use combinedText.split()) and assign the resultant list to “words” • Step 5. Find the unique words in “words” and assign the resultant list to “unique_words” • Step 6. Create an empty list named “word_freqs” • Step 7. Define a variable “word” in a for loop to iterate over “unique_words” – Step 8. Count the number of times “word” appears in “words” (you can use words.count(word)) and append the count to “word_freqs” • Step 9. Find the index of maximum value of “word_freqs”. (I suggest you to use numpy.argmax(word_freqs) where numpy is an external library that needs to be imported to your Python session.) And provide this index to “unique_words” to find the most common word.
04-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值