我有三个清单:
name = ['rob', 'mike', 'bob']
age = ['19, '32', '88']
id = ['aaa', 'bbb', 'ccc']
有没有办法垂直连接这些并获得如下的CSV?
rob, 19, aaa
mike, 32, bbb
bob, 88, ccc
答案 0 :(得分:1)
for i,j,k in zip(name, age, id):
print ('{}, {}, {}'.format(i,j,k))
输出:
rob, 19, aaa
mike, 32, bbb
bob, 88, ccc
答案 1 :(得分:1)
答案 2 :(得分:0)
您可以使用csv模块和import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class SearchPage extends JFrame {
private JTextField searchField;
private JButton searchButton;
private ItemPage itemPage;
SearchPage(){
setSize(200,100);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
searchField = new JTextField(9);
add(searchField, BorderLayout.NORTH);
searchButton = new JButton("Search");
searchButton.addActionListener(e -> {
String searchFor = searchField.getText();
if ((searchFor != null) && ! searchFor.isEmpty()) {
itemPage.search(searchFor);
}
});
add(searchButton, BorderLayout.SOUTH);
itemPage = new ItemPage();
setVisible(true);
}
public static void main(String[] args) {
new SearchPage();
}
}
class ItemPage {
public void search(String searchFor) {
System.out.println("Searching for "+ searchFor);
}
}
来执行此操作。
zip
输出: