Lab 4
Optional: no Lab 4 due to Rally Day
So in this case, the element -1 was at index 3, the -3 was at index 10, and so on. Here is the list so you don't have to type it in:
[12, 5, 6, -1, 17, 2, 15, 19, 18, 14, -3, 7, -4, 16, 0, 4, 8, -5, 13, 1]Now modify your function so that it changes the negative numbers to 0. After you're finished, this function shouldn't print or return anything, but modify the original list. An example is shown below:
Try a few different lists to make sure your function works in general.
Then, use list indexing to obtain the first and last elements of this list. Finally, use list slicing to obtain the range of numbers between the first and last negative numbers in the original list. An example is shown below:
Note that in this example, the "mid range" list starts at the element 17 and goes to the element 8, since -1 was the first negative number, and -5 was the last. Test your function on other lists to make sure it works in general. When you're sure it's working, remove any print statements (usually I comment them out in case I need them later). Then make sure you can store the return value to another variable (here called middle_lst):
In this example, the character "i" first appears at index 3, the character "t" first appears at index 1, etc.
To use this built-in function with tweets, create a new function called get_hashtag(tweet), which takes one parameter, a string representing the tweet. First find the index of the first occurrence of a hashtag ("#"). Then use list slicing to obtain the portion of the string after (and including) that hashtag. Here is an example of what your code should produce when your method is run on each tweet separately:
Finally, modify your method so that it prints out the (multiple) hashtags one by one, but not including the symbol "#". You should get something like this: