如何解决如何拆分数据以在python中获得所需的输出?
我有一个输入,我想分割文本以获得我曾经使用过的import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class SimpleAnimation {
int x = 70;
int y = 70;
int tick = 0;
public static void main(String[] args) {
SimpleAnimation gui = new SimpleAnimation();
gui.go();
}
public void go() {
System.out.println("go");
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDrawPanel mdp = new MyDrawPanel();
frame.getContentPane().add(mdp);
frame.setSize(300,300);
frame.setVisible(true);
System.out.println("go");
Timer timer = new Timer(50,new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tick++;
if (tick > 129) {
((Timer)e.getSource()).stop();
}
x++;
y++;
mdp.repaint();
}
});
timer.start();
}
class MyDrawPanel extends JPanel {
public MyDrawPanel() {
setBackground(Color.WHITE);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.green);
g.fillOval(x,y,40,40);
}
}
}
所需的输出,但这并不能解决我的问题。需要python编码新的帮助。
输入:txt.split(":")[-1]
所需的输出:End Date: 10-09-2020 10:00 AM
解决方法
尝试:
input = "End Date: 10-09-2020 10:00 AM"
matcher = "End Date: " # get a constant identifier to look for
# now we want to slice the string in such way that leaves only the part
# after the matcher. So we find the first occurence of matcher and then
# add it's length to see where is the end of the matcher. then we
# simply take the remaining string
desired = input[input.find(matcher)+len(matcher):]
,
txt.split("End Date:")[-1]
它将解决问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。