-2

The prompt:

Write a sequence of statements that finds the first comma in the string associated with the variable line, and associates the variable clause the portion of line up to, but not including the comma.

I am stuck. All I could understand and come up with was two statements (variables). First comma in the string associated with the variable line, makes me think of line equal line, and clause equal

Blockquote

line = line,
clause = "line"

Second attempt- still not working but I'm getting there now that I know to focus on find, index, or split

line = ""
clause = line.find("," [0[line]])

Attempt three, the split works but the issue is the line statement and it is by omitting the line statement that it finally works. Thanks so much!

clause = line.split(",")[0]
Paul Bernella
  • 31
  • 1
  • 4
  • 13
  • `i = string.find("{},".format(line));print(s[:i]) `? What is the actual input like? – Padraic Cunningham Sep 20 '15 at 22:07
  • The idea, I believe, is that line contains some string, and you need to write code that determines where in that string is the first comma, and uses that information to isolate the part of the string before it. – Scott Hunter Sep 20 '15 at 22:09
  • 1
    this smells of assigned work and lack of sweat :/ – Shawn Mehan Sep 20 '15 at 22:10
  • Oh, okay. So i set up a statement that searches for the first comma then....I see. Yup, it's assigned work and I've been racking my brain, checking the textbook and looking at the resources online. All right Let me look at that string unit again – Paul Bernella Sep 20 '15 at 22:12

2 Answers2

2

Okay, so it seems that you are having trouble understanding the actual statement, let's analyse what is being asked of you:

Write a sequence of statements that finds the first comma in the string associated with the variable line (...)

so, you create a variable line and associate a string to it, more specifically, a string that has a comma (that we are going to find).

line = 'this is an example string, this is never going to be seen.'

(...) and associates the variable clause the portion of line up to, but not including the comma.

Now you need to create another variable clause that is going to be associated with that portion of the string BEFORE the comma (but excluding the comma), that is: 'this is an example string'

clause = line.split(',')[0]

All this code does is, it splits line where commas are and creates a list with the results, with the [0] you are accessing the first element of that list. Simple right?

0
clause=line[0: line.find(",")]
Ridhi
  • 105
  • 8