• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
oooooolr
You can do anything but not everything. ——David Allen
博客园    首页    新随笔    联系   管理    订阅  订阅

kaggle learn python

def has_lucky_number(nums):
    return any([num % 7 == 0 for num in nums])

 

def menu_is_boring(meals):
    """Given a list of meals served over some period of time, return True if the
    same meal has ever been served two days in a row, and False otherwise.
    """
    for meal in meals:
        next = meals.index(meal)+1
        try:
            if meal == meals[next] :
                return True
        except:
                return False 
#     else:
#         return False
meals=['Spam', 'Eggs', 'Bacon', 'Spam']
menu_is_boring(meals)
为什么不能返回数据啊!!!
竟然用len(meals)-1来解决了。。。。

 

str = "123abcrunoob321"
print (str.strip( '12' )) 
result:
3abcrunoob3
以上下例演示了只要头尾包含有指定字符序列中的字符就删除
map(lambda x:x.strip(',.'),doc.lower().split())

dic 没有append 方法

 

#         2 decimal points   3 decimal points, format as percent     separate with commas
"{} weighs about {:.2} kilograms ({:.3%} of Earth's mass). It is home to {:,} Plutonians.".format(
    planet, pluto_mass, pluto_mass / earth_mass, population,
)
result:
"Pluto weighs about 1.3e+22 kilograms (0.218% of Earth's mass). It is home to 52,910,390 Plutonians."
 
['K']
[10 if x in'KQJ' else x for x in hand_1]

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- focus on what you want to be
posted @ 2019-03-24 21:47  oooooolr  阅读(308)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3