在一行上打印两个列表

时间:2015-11-08 12:12:57

标签: python

我有两个清单。

> o<- out %>% group_by(site) %>% mutate(row = paste0("corr", row_number()))
Error in rank(x, ties.method = "first", na.last = "keep") : 
  argument "x" is missing, with no default

>dput(out)
structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2001", "2002", 
"2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", 
"2011", "2012", "2013", "2014", "2015", "2016", "2017", "2020", 
"2021", "2022", "2102", "2107", "2108"), class = "factor"), corr = c(1, 
0.96999258460714, 0.940002658241897, 0.912152752891952, 0.884318687047626, 
0.857969509223287, 0.832630705318952, 0.807620983310881, 0.783158970946845, 
1, 0.967337226340769, 0.930786616932812, 0.893007333276278, 0.855745958730318, 
0.819162237318344, 0.784067927740006)), .Names = c("site", "corr"
), row.names = c(NA, 16L), class = "data.frame")

..我想在一行上打印每个列表的每个元素。因此,它会在第二行显示SpeedList = ["25","30"] NameList = ["John Smith","Tom Smith"] John Smith was driving at 25 mph的内容。

我试过了:

Tom Smith was driving at 30 mph

但它打印出来:

print (NameList)," Was driving at ",(SpeedList), " mph."

2 个答案:

答案 0 :(得分:2)

喜欢这个吗?

>>> SpeedList = ["25","30"]
>>> NameList = ["John Smith","Tom Smith"]
>>> for name, speed in zip(NameList, SpeedList):
...     print (name)," Was driving at ",(speed), " mph."
... 
John Smith  Was driving at  25  mph.
Tom Smith  Was driving at  30  mph.
>>> 

答案 1 :(得分:0)

name=["John Smith", "Tom Smith"]
speed=["25", "30"]
for i in range(2):
    e=name[i]
    f=speed[i]
    result=e + " was driving at " + f + "mph."
    print result
相关问题