Code Signal_练习题_Add Border
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的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- 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) + ...
随机推荐
- socketserver模块解析
socketserver模块是基于socket而来的模块,它是在socket的基础上进行了一层封装,并且实现并发等功能. 看看具体用法: x import sockets ...
- 【python】10分钟教你用python打造贪吃蛇超详细教程
10分钟教你用python打造贪吃蛇超详细教程 在家闲着没妹子约, 刚好最近又学了一下python,听说pygame挺好玩的.今天就在家研究一下, 弄了个贪吃蛇出来.希望大家喜欢. 先看程序效果: 0 ...
- java连接hbase时出现....is accessible from more than one module:
今天在用java程序连接hbase时,出现错误,The package org.apache.hadoop.hbase is accessible from more than one module: ...
- 为阿里云域名配置免费SSL支持https加密访问简单教程
阿里云之前有免费ssl入口申请,现在已经关闭了.那么现在怎么为自己的域名配置https呢? 首先打开阿里云域名控制台,如以下界面.(这里暂且用我的这个域名讲解吧) 如上图点击ssl证书,点击单域名免 ...
- 图的最短路径---弗洛伊德(Floyd)算法浅析
算法介绍 和Dijkstra算法一样,Floyd算法也是为了解决寻找给定的加权图中顶点间最短路径的算法.不同的是,Floyd可以用来解决"多源最短路径"的问题. 算法思路 算法需要 ...
- ReactNative常用组件库 victory-native 图表
victory-native 是不错的图表组件,支持很多种图表 地址: https://github.com/FormidableLabs/victory-native 先安装 react-nativ ...
- dp--2019南昌网络赛B-Match Stick Game
dp--2019南昌网络赛B-Match Stick Game Xiao Ming recently indulges in match stick game and he thinks he is ...
- SpringSecurity之记住我功能的实现
Spring security记住我基本原理: 登录的时候,请求发送给过滤器UsernamePasswordAuthenticationFilter,当该过滤器认证成功后,会调用RememberMeS ...
- python-select异步IO
#实现多任务在同一个线程切换 #!/usr/bin/python from socket import * from select import * from time import ctime so ...
- python-Event事件线程同步和互斥
#!/usr/bin/python #coding=utf-8 #用于线程间通信,通过事件标识控制 import threading from time import sleep,ctime def ...