Given a rectangular matrix of characters, add a border of asterisks(*) to it.

Example

For

picture = ["abc",
"ded"]

the output should be

addBorder(picture) = ["*****",
"*abc*",
"*ded*",
"*****"]
我的解答:
 永远都是最笨的方法........
def addBorder(picture):
for i in range(len(picture)):
picture[i] = '*'+picture[i]+'*'
picture.insert(0,'*'*(len(picture[0])))
picture.append('*'*(len(picture[0])))
return picture

膜拜大佬:


def addBorder(picture):
l=len(picture[0])+2
return ["*"*l]+[x.center(l,"*") for x in picture]+["*"*l]

 

Code Signal_练习题_Add Border的更多相关文章

  1. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  2. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  3. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  4. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  5. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  6. Code Signal_练习题_firstDigit

    Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...

  7. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  8. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

  9. Code Signal_练习题_absoluteValuesSumMinimization

    Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...

随机推荐

  1. Nginx的反向代理和负载均衡

    1 Nginx的反向代理 1.1 什么是反向代理 正向代理 反向代理: 反向代理服务器是引用在服务端.决定哪台服务器提供服务. 1.2 反向代理的模拟 1.2.1 反向代理 应该有一个nginx服务器 ...

  2. Mutation Observer

    MutationEvent Mutation Observer 变动观察器, 等待所有脚本任务完成后,才会运行(即异步触发方式) 把DOM变动记录封装成一个数组进行处理,而不是一条条个别处理DOM变动 ...

  3. TSL协议升级导致的问题:caught when processing request: Received fatal alert: protocol_version

    近日,公司升级TSL协议,禁用TSL1.0,导致原本好好的https接口,报以下错误: 2019-03-05 15:43:29 [org.apache.commons.httpclient.HttpM ...

  4. Python中的匿名函数lambda的用法

    一.lambda函数的简介  对lambda函数,它其实是一个类似于def的函数,只不过lambda是一个不需要定义函数名的匿名函数.当我们在有些时候,需要做一些简单的数学计算时,如果定义一个def函 ...

  5. SHELL脚本进阶

    一.读取参数 $0 程序名称$1 第一个参数$2 第二个参数,依次类推可以使用 basename 来读取程序名称:basename $0 可以使用 dirname 来读取第一个参数的目录:dirnam ...

  6. javascript004_ECMA5数组新特性

    •对于ECMAscript5这个版本的Array新特性补充: –位置方法:indexOf      lastIndexOf –迭代方法:every  filter   forEach   some   ...

  7. ok6410 android driver(2)

    I will paste and anlaysis a small character device driver in this paragraph. #include <linux/modu ...

  8. 微服务Kong(四)——添加插件

    在本节中,您将学习到,如何配置使用KONG的插件来管理您的API.KONG的核心原则之一就是通过插件来实现API的扩展.插件可以使您更为简单的扩展和管理您的API. 在以下的步骤中,您将通过配置key ...

  9. Linux-socket使用

    socket 产生的原因 进程通信的概念最初来源于单机系统.由于每个进程都在自己的地址范围内运行,为保证两个相互通信的进程之间既互不干扰又协调一致工作,操作系统为进程通信提供了相应设施,如 UNIX ...

  10. teleport助手不可以使用剪切板的问题解决

    在使用teleport堡垒机的时候,你使用teleport助手会发现不可以使用剪切板,接下来就是解决方法. 解决办法:更新freerdp 基于环境:win10(win7下更新好像没有用),telepo ...